Canvas Canvas - 4 months ago 31
jQuery Question

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

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 );
});
});

Answer

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).

Comments