我需要解析这个 JSON 链接
http://www.mse.mk/FreeMseFeeds/service/FreeMSEFeeds.svc/ticker/JSON/9538ac69-2c99-45ba-bbd4-90931ca0cc7d
与本页相同:
http://www.mse.mk/en/
图片: http://tinypic.com/r/1zlyhwo/8我尝试过这样的:
$.getJSON("http://www.mse.mk/FreeMseFeeds/service/FreeMSEFeeds.svc/ticker/JSON/9538ac69-2c99-45ba-bbd4-90931ca0cc7d",function(data){
alert(data[0].name);
});
我收到此错误:
XMLHttpRequest cannot load http:// www.mse.mk/FreeMseFeeds/service/FreeMSEFeeds.svc/ticker/JSON/9538ac69-2c99-45ba-bbd4-90931ca0cc7d. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http: //kristijanz.com' is therefore not allowed access.
有什么帮助吗?
最佳答案
看起来像是 CORS 问题 - 您调用 www.mse.mk/FreeMseFeeds/service/FreeMSEFeeds.svc/ticker/JSON/9538ac69-2c99-45ba-bbd4-90931ca0cc7d
的应用程序未运行相同的域。
如果您控制服务,则可以实现 CORS 以允许其他域来源。
如果不这样做,您将无法从您的域调用此服务。
CORS - https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
关于javascript - 使用 jquery 将 JSON 解析为 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31855428/