We are trying to hit the meetup.com api using jquery's getJSON() method and are running into some problems. In firebug we can run
我们试图使用jquery的getJSON()方法点击meetup.com api并遇到一些问题。在萤火虫中我们可以跑
$.getJSON(
'http://api.meetup.com/events.json?group_urlname=Closing-the-NOLA-Gap&key=ourkey',
function(data) { console.log(data) }
);
We can see the call taking some time. We can inspect the response header and see the content size is 42K, yet the content body (as shown by firebug) is empty! How is this possible?
我们可以看到通话需要一些时间。我们可以检查响应头并看到内容大小是42K,但内容正文(如firebug所示)是空的!这怎么可能?
When we point to the url in the browser we have all the appropriate json formatted text appear on the page.
当我们指向浏览器中的url时,我们会在页面上显示所有相应的json格式文本。
What are we missing?
我们缺少什么?
PS. We've tried $.ajax, and $.get - same results with each. We also tried it with 3 parameters where the first is url, the second is null, and the third is the callback.
PS。我们尝试了$ .ajax和$ .get - 每个都有相同的结果。我们还尝试了3个参数,其中第一个是url,第二个是null,第三个是回调。
1 个解决方案
#1
5
Make sure you have callback=?
in the querystring of the URL you're hitting...since it's a remote domain, you need to use JSONP here (which callback=?
triggers). Like this:
确保你有回调=?在您要访问的URL的查询字符串中...因为它是一个远程域,您需要在这里使用JSONP(哪个回调=?触发器)。喜欢这个:
$.getJSON(
'http://api.meetup.com/events.json?group_urlname=Closing-the-NOLA-Gap&key=ourkey&callback=?',
function(data) { console.log(data); }
);
From the $.getJSON()
docs:
来自$ .getJSON()文档:
If the URL includes the string
"callback=?"
in the URL, the request is treated as JSONP instead. See the discussion of thejsonp
data type in $.ajax() for more details.如果URL包含字符串“callback =?”在URL中,请求被视为JSONP。有关更多详细信息,请参阅$ .ajax()中有关jsonp数据类型的讨论。
#1
5
Make sure you have callback=?
in the querystring of the URL you're hitting...since it's a remote domain, you need to use JSONP here (which callback=?
triggers). Like this:
确保你有回调=?在您要访问的URL的查询字符串中...因为它是一个远程域,您需要在这里使用JSONP(哪个回调=?触发器)。喜欢这个:
$.getJSON(
'http://api.meetup.com/events.json?group_urlname=Closing-the-NOLA-Gap&key=ourkey&callback=?',
function(data) { console.log(data); }
);
From the $.getJSON()
docs:
来自$ .getJSON()文档:
If the URL includes the string
"callback=?"
in the URL, the request is treated as JSONP instead. See the discussion of thejsonp
data type in $.ajax() for more details.如果URL包含字符串“callback =?”在URL中,请求被视为JSONP。有关更多详细信息,请参阅$ .ajax()中有关jsonp数据类型的讨论。