Chrome原始空值不被Access-Control-Allow-Origin允许 [英] Chrome Origin null is not allowed by Access-Control-Allow-Origin

查看:299
本文介绍了Chrome原始空值不被Access-Control-Allow-Origin允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经准备好了许多其他帖子,这里有人问过关于原产地不允许使用blablabla,

现在我试着添加--Access-Control-Allow -Origin和启用应用程序,甚至禁用安全性,但每次我尝试我的按钮在PHP页面上它只是说明

  Origin null Access-Control-Allow-Origin不允许。 

任何人都可以帮助我吗?这是导致问题的代码



page.php

 < html land =en> 
< head>
< meta carset =utf-8>
< link rel =stylesheettype =text / csshref =style.css;
< / head>

< body>
<! - 文件就绪事件 - >
< input id =texttype =text/>< input id =submittype =buttonvalue =Submit/>

< div id =feedback>< / div>
< script src =../ jquery-1.10.2.min.js>< / script>
< script src =script.js>< / script>
< / body>
< / html>

Script.js

  $('#submit')。click(function()
{
var text = $('#text')。val();

$ .get('PHP / reverse.php',{input:text},function(data)
{
$('#feedback').text(data);
} );
});


解决方案

通过Access-Control-Allow-Origin 表示您正在尝试在本地文件上执行Ajax。出于安全原因,这是禁止的。即使情况并非如此,您的PHP将无法运行,因为PHP受Web服务器支持,而不是Web浏览器。



您安装了Web服务器。您必须通过服务器请求您的页面,而不是直接从您的文件系统访问它们。



使用以 http://开头的URL localhost /



您需要移动文件,使其位于服务器的 DocumentRoot

I have ready many of the other posts ppl have asked here about the origin not allowed blablabla,

Now I have tried to add --Access-Control-Allow-Origin and enable apps and even disabled security but every time I try my button on the php page it just keeps stating

Origin null is not allowed by Access-Control-Allow-Origin.

Can anyone help me at all? Here is the code that is causing the problem

page.php

<html land="en">
<head>
    <meta carset="utf-8">
    <link rel="stylesheet" type="text/css" href="style.css";
</head>

<body>
<!-- Document Ready Event -->
<input id="text" type="text" /><input id="submit" type="button" value="Submit" />

<div id="feedback"></div>
    <script src="../jquery-1.10.2.min.js"></script>
    <script src="script.js"></script>
</body>
</html>

Script.js

$('#submit').click( function()
{
var text = $('#text').val();

$.get( 'PHP/reverse.php', { input: text }, function( data )
    {
        $('#feedback').text( data );
    });
});

解决方案

Origin null is not allowed by Access-Control-Allow-Origin means that you are trying to perform Ajax on a local file. This is forbidden for security reasons. Even if this was not the case, your PHP wouldn't run because PHP is supported by web servers, not web browsers.

You have a web server installed. You have to request your pages through the server, rather than accessing them directly from your file system.

Use a URL starting with http://localhost/

You will need to move your files so that they are under the server's DocumentRoot (or reconfigure the server so that it can access them from their present location).

这篇关于Chrome原始空值不被Access-Control-Allow-Origin允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆