jQuery getJson 返回 null

发布于 2024-09-01 21:45:11 字数 468 浏览 8 评论 0原文

我正在尝试使用这个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

手心的海 2024-09-08 21:45:16

key=MYAPIKEY=John+3:16-18

参数值是否已进行 URL 编码?看起来没有。 =+:URL 中的保留字符

试试这个:

key=MYAPIKEY%3DJohn%2B3%3A16-18

要在 JS 中自行执行此操作,请通过 encodeURIComponent() 并在查询字符串中使用其返回值。

key=MYAPIKEY=John+3:16-18

Is the parameter value already URL-encoded? Look like not. The =, + and : are reserved characters in an URL.

Try this instead:

key=MYAPIKEY%3DJohn%2B3%3A16-18

To do this yourself in JS, pass MYAPIKEY=John+3:16-18 through encodeURIComponent() and use its return value in the query string.

阪姬 2024-09-08 21:45:16

我很确定您遇到了跨域请求限制。最好的选择是使用 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)

掩于岁月 2024-09-08 21:45:15

试试这个,只是为了测试:

$.ajax({
  url: 'http://api.biblia.com/v1/bible/content/KJV.json?key=MYAPIKEY=John+3:16-18&style=bibleTextOnly',
  dataType: 'json',
  success: function(data) { alert(data); }
});

这对你有用吗?

Try this out instead, just for testing:

$.ajax({
  url: 'http://api.biblia.com/v1/bible/content/KJV.json?key=MYAPIKEY=John+3:16-18&style=bibleTextOnly',
  dataType: 'json',
  success: function(data) { alert(data); }
});

Does that work for you?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文