我正在用这个
$.getJSON('localhost/api/getStoreInventory', data, function(json) {});
对我正在处理的 api 进行 json 调用。只要我使用 localhost,一旦我将其更改为我的产品服务器 ex:
$.getJSON('http://mydomain.com/api/getStoreInventory',
data, function(json) {});
调用将会失败。本地主机和生产环境中的两个 api 文件是相同的。我运行了 api 通过 JSLint.com json 验证器返回的 json,它报告我的 json 在默认设置下效果良好。任何帮助将不胜感激。
最佳答案
您无法发出跨域 ajax 请求。
http://usejquery.com/posts/9/the-jquery-cross-domain-ajax-guide
关于javascript - 为什么 JSON 通过 jslint.com 测试时 $.getJSON 会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7128024/