问题
Here is live HTTP stream that delivers streaming JSON objects using chunked transfer encoding: http://stream.meetup.com/2/rsvps
Is it possible to parse this JSON request using jQuery getJSON ? I want to get each item as it comes in and insert new image tag with the image. Like the function I wrote below, but doesn't work
$.getJSON("http://stream.meetup.com/2/rsvps", displayImages);
function displayImages(data) {
$.each(data.results, function(i,item) {
$("<img/>").attr("src", item.member.photo).appendTo('#images');
});
}
回答1:
You cannot make cross-domain ajax requests due to the same origin policy. You can use JSONP to sidestep the problem, but the web service needs to support it.
It looks like the Meetup API supports JSONP, though naturally JSONP can't handle streaming-style updates.
来源:https://stackoverflow.com/questions/5927932/parse-live-stream-http-chunked-transfer-json-with-jquery