0
我刚刚了解到,使用getJson与来自其他域/端口的url通常会导致跨域策略问题。getJson访问控制 - 允许来源
有了这个代码:
var appGetApi = "http://localhost:30028/api/values";
$.getJSON(appGetApi, function (_returnedJson) {
...
});
我得到这个错误:
XMLHttpRequest cannot load http://localhost:30028/api/values.
Origin http://localhost:17437 is not allowed by Access-Control-Allow-Origin.
在网上搜索答案后,似乎增加&回调=?是一个着名的修复程序。所以我做到了。
var appGetApi = "http://localhost:30028/api/values&callback=?";
$.getJSON(appGetApi, function (_returnedJson) {
...
});
但我仍然得到一个错误:
Failed to load resource: the server responded with a status of 400 (Bad Request)
http://localhost:30028/api/values&callback=jQuery11020629610788077116_1373178114158?_=1373178114159
这是我第一次与API和我现在在如何解决这个问题是完全无能。请帮助我们。谢谢。