dustcomposer Posted October 23, 2014 Share Posted October 23, 2014 I'm trying this w3schools tutorial about JsonHttp. All setted up but catch an error: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. I surfed to find solution but some suggest to use php. w3schools doesn't say anything about php in the tutorial above, so I get confused as I don't use php. All I want to do is open a .txt file (contains json) and access its some values. Any help? Thanks! * I run the function (js) from my pc to access .txt file which uploaded to a server. Link to comment Share on other sites More sharing options...
Ingolme Posted October 23, 2014 Share Posted October 23, 2014 Two things: XMLHTTP requests don't work on the local filesystem for some browsers for security reasons. The second thing is that you cannot request a file that´s on a different domain name unless the server has been programmed to send a particular header in the response. Here's a page explaining about cross-domain requests: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS Link to comment Share on other sites More sharing options...
dustcomposer Posted October 23, 2014 Author Share Posted October 23, 2014 so what should I do to get the tutorial work, can I simply upload the html page along with the js to the same folder where the .txt is (my web server)? Thanks Ingolme. Link to comment Share on other sites More sharing options...
Ingolme Posted October 23, 2014 Share Posted October 23, 2014 If all the files are under the same domain name then it should work without any problem. Link to comment Share on other sites More sharing options...
dustcomposer Posted October 24, 2014 Author Share Posted October 24, 2014 Yes, it all works fine and doesn't have to be in the same folder. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now