Reputation: 1677
I have a simple jQuery post function that calls PHP script in order to return value from the database.
In Firebug I see that the PHP file is being called with 200 OK status, however the success function in JS is not being called.
To test the problem I have changed the PHP to only echo a simple string, but it doesn't work as well.
When I view the PHP file directly in the browser I do see the echoed string.
Here is the JS code:
$.post(PATH + "load.php", { id: _id },
function (data) {
console.log("LOADED " + data);
});
And here is the simple PHP code:
<?
echo "bla bla bla"
?>
I don't know what the problem is. My HTML+JS file is local and it calls an online PHP file. Maybe this is the reason? Any help will be appreciated.
Upvotes: 2
Views: 171
Reputation: 5512
My HTML+JS file is local and it calls an online PHP file. Maybe this is the reason?
Answer: Yes
Reason: Same origin policy rule
http://en.wikipedia.org/wiki/Same_origin_policy
Grant Thomas suggested a possible workaround: you can delegate the call to a method on same-origin server which calls external resource.
Upvotes: 4