jQuery getJson 返回 null
我正在尝试使用这个 api 来引用精确的文本,但 getJson 似乎不起作用,它只是返回 null。
$.getJSON('http://api.biblia.com/v1/bible/content/KJV.json?key=MYAPIKEY=John+3:16-18&style=bibleTextOnly', function(data) {
alert(data);
});
我刚刚拿出了密钥,我一直在用我的真实 api 密钥对其进行测试,当我访问该 url 时它工作正常。我还需要做些什么才能让它发挥作用吗?
这是当你在 url 中有一个 api key 时从 url 得到的结果:
{"text":"神如此爱世人,甚至将他的独生子赐给他们,叫一切信他的,不至灭亡,反得因为神差他的儿子降世,不是要定世人的罪,而是要叫世人因他得救;不信的人,已经被定罪了,因为他还没有信。以上帝独生子的名义。”}
I'm trying to use this api that lets you reference an exact text, but the getJson does not seem to be working, it's just returning null.
$.getJSON('http://api.biblia.com/v1/bible/content/KJV.json?key=MYAPIKEY=John+3:16-18&style=bibleTextOnly', function(data) {
alert(data);
});
I just took the key out, i've been testing it with my real api key, and it works fine when i just visit the url. is there anything else i need to do to make it work?
This is what you get from the url when you have an api key in the url:
{"text":"For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. For God sent not his Son into the world to condemn the world; but that the world through him might be saved. He that believeth on him is not condemned: but he that believeth not is condemned already, because he hath not believed in the name of the only begotten Son of God."}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
参数值是否已进行 URL 编码?看起来没有。
=
、+
和:
是 URL 中的保留字符。试试这个:
要在 JS 中自行执行此操作,请通过
encodeURIComponent()
并在查询字符串中使用其返回值。Is the parameter value already URL-encoded? Look like not. The
=
,+
and:
are reserved characters in an URL.Try this instead:
To do this yourself in JS, pass
MYAPIKEY=John+3:16-18
throughencodeURIComponent()
and use its return value in the query string.我很确定您遇到了跨域请求限制。最好的选择是使用 JSONP 而不是 JSON(假设 api.biblia.com 支持 JSONP):
http://api.jquery.com/jQuery.ajax(请参阅该页面上 JSONP 数据类型的讨论)
I'm pretty sure you're running into cross-domain request restrictions. Your best bet is to use JSONP instead of JSON (assuming api.biblia.com supports JSONP):
http://api.jquery.com/jQuery.ajax (see discussion of JSONP data type on that page)
试试这个,只是为了测试:
这对你有用吗?
Try this out instead, just for testing:
Does that work for you?