简体   繁体   中英

JSON is not Retrieved When Put on the Server but Does Work on Localhost using XAMPP

I'm having a problem, my code works in XAMPP. However, it is not working once I put it in the server, I host it with fatcow, it seems that they work json and php 5.2.

I'm using Jquery and Json, two commands I'm using to retrive the data $.getJSON and $.post, I'm using two libraries src="http://code.jquery.com/jquery-latest.js" type="text/javascript"> jquery.json.js

I have no clue what is the problem, the json encode outputs json data, but my code from js doesn't retrive it doesn't seem that it copies to the array i have with $.getJson. I dont understand, all help will be greatly appretiated.

Looks like your JSON data is not returned due to the Cross Origin Resource Sharing policy (CORS).

You can solve this problem by:

  • Putting the JSON file in the same domain as the Javascript/HTML file that requests it

OR

  • By adding the header:

    Access-Control-Allow-Origin: *

to your JSON file.

More information on how to add CORS headers

More information on CORS

Hope that helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM