1

When I run my page in Safari, the JSON file loads successfully, but fails when I run it in Chrome. In the error console in Chrome it displays this error:

XMLHttpRequest cannot load file:///C:/Users/290851/Desktop/json-eg/test.json. Origin null is not allowed by Access-Control-Allow-Origin.

I also tested the JSON file and it's valid. Can someone tell me why this is happening and what is the solution for it?

Perception
  • 75,573
  • 19
  • 170
  • 185
Mak
  • 482
  • 1
  • 10
  • 32
  • You are running afoul of the same-origin-policy restriction in Chrome. See here for an example of how to get around this - http://stackoverflow.com/questions/3102819/chrome-disable-same-origin-policy – Perception May 23 '12 at 04:15
  • Check out this other answer to see if it helps: [enter link description here][1] [1]: http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin – Ed Harling May 23 '12 at 04:17

1 Answers1

1

Have you heard of Cross Domain Access??

You will not be able to call the service (a jason file in your case) in another domain. Chrome gives you the warning mesg that the script and the service are located in different domains (different sites). This is a security feature in modern browsers which prevents such web calls.

If you have both script and the jason file and the jason file in the same folder I guess it should world. Give it a try and see.

You need to use Proxy or JSONP to over come this issue.

There are many similar questions asked previously check them out too.

Community
  • 1
  • 1
Jay Mayu
  • 15,955
  • 31
  • 111
  • 144