how to kill an older jsonp request?

Posted by pfg on Stack Overflow See other posts from Stack Overflow or by pfg
Published on 2010-05-04T12:45:05Z Indexed on 2010/05/04 12:48 UTC
Read the original article Hit count: 176

Filed under:

I have a cross-domain long polling request using getJSON with a callback that looks something like this:

$.getJSON("http://long-polling.com/some.fcgi?jsoncallback=?" function(data){ if(data.items[0].rval == 1) { // update data in page } });

The problem is the request to the long-polling service might take a while to return, and another getJSON request might be made in the meantime and update the page even though it is a stale response.

Req1: h**p://long-polling.com/some.fcgi at 10:00 AM

Req2: h**p://long-polling.com/some.fcgi? at 10:01 AM

Req1 returns and updates the data on the page 10:02 AM

I want a way to invalidate the return from Req1 if Req2 has already been made.

Thanks!

© Stack Overflow or respective owner

Related posts about jsonp