Question

I'm getting the following error in Chrome:

XMLHttpRequest cannot load 'http://localhost/getuser.php?q=1&sid=0.03709745453670621'. Origin null is not allowed by Access-Control-Allow-Origin.

When I click on the link 'http://localhost/getuser.php?q=1&sid=0.03709745453670621'. It displays the correct data but I don't understand why I keep getting this error and I can't figure out how to --allow-file-access-from-files.

When I run it in Firefox, I get no error but data isn't displayed either. In Javascript code, alert(xmlHttp.responseText) shows nothing which is because the responseText contains empty String. Why doesn't it contain array data?

Was it helpful?

Solution

The issue came up because of the same-origin policy. Adding header('Access-Control-Allow-Origin: *'); on top of my php file helped resolved the issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top