JQuery ajax getJSON answer has size but empty body?

We are trying to use the meetup.com api application using the jquery getJSON () method and are facing some problems. In firebug we can run

$.getJSON(
'http://api.meetup.com/events.json?group_urlname=Closing-the-NOLA-Gap&key=ourkey', 
function(data) { console.log(data) }
);

We can see that the call takes some time. We can check the response header and see that the content size is 42 KB, but the content body (as shown by Firebug) is empty! How is this possible?

When we point to the URL in the browser, the corresponding text in json format will appear on the page.

What are we missing?

PS. We tried $ .ajax and $ .get - the same results with each. We also tried this with three parameters, where the first is the url, the second is null, and the third is the callback.

+3
source share
1 answer

Make sure you have the callback=?URL in the query string that you click ... since this is a remote domain, you need to use JSONP here (which works callback=?). Like this:

$.getJSON(
 'http://api.meetup.com/events.json?group_urlname=Closing-the-NOLA-Gap&key=ourkey&callback=?', 
 function(data) { console.log(data); }
);

From $.getJSON()docs:

If the URL contains a string "callback=?"in the URL, the request is processed as JSONP. See the discussion of the data type jsonpin $ for more details . Ajax () .

+5
source

Source: https://habr.com/ru/post/1755231/


All Articles