【发布时间】:2015-04-01 16:24:19
【问题描述】:
我正在尝试使用以下内容从 Worldcat 获取有关某些书籍的元数据:
$.getJSON( " http://xisbn.worldcat.org/webservices/xid/isbn/" + $isbn[1] + "?method=getMetadata&format=json&callback=mymethod&fl=*");
其中 $isbn[1] 是十位或十三位数字(0123456789 有效)。
我可以输入http://xisbn.worldcat.org/webservices/xid/isbn/0123456789?method=getMetadata&format=json&callback=mymethod&fl=* 并得到我需要的结果,但我不会跨域这样做。
控制台正在报告XMLHttpRequest cannot load http://xisbn.worldcat.org/webservices/xid/isbn/0123456789?method=getMetadata&format=json&callback=mymethod&fl=*. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.
我在 jsfiddle 上做这一切。想也许这可能是我在本地尝试过的问题,但没有区别。我做错了什么?
【问题讨论】:
-
如果你得到一个 cors 错误,你没有发出 jsonp 请求。您不应该自己指定方法,而是应该使用
??作为文档中指定的回调。 -
好的,我后来有了,但这还不够/不起作用?
mymethod = function(data){ alert(data.foo); }; -
@KevinB,如果回调变量存在则为真。但是就像你说的那样,它必须是
? -
@pr3sidentspence 请提供您尝试使用
callback=??的代码示例。它对我有用。
标签: javascript jquery json cross-domain jsonp