views:

181

answers:

2

I'm using...

   $.getJSON(url + "&callback=?", function (b) {
                .......
   });

for a long-polling request. Sometimes it is necessary that I stop the current request being made. Is this possible?

+2  A: 

I think this works, but have never tried it for myself...

var theRequest = $.getJSON(url + "&callback=?", function (b) {
            .......
});

theRequest.abort();  // aborts the xmlhttprequest made

$.getJSON() should return the XMLHTTPRequest object, upon which you call the abort() method.

patrick dw
Thanks, this definitely looks promising...I'll try it out.
Chris
A: 

Not sure if you're aborting because it's taking too long, but if so you can change your $.getJSON call to $.ajax and set a timeout:

$.ajax({url: url, dataType:'json', data: "param1=" + params,timeout: 7000, success:resultsHandler })
derek
It's not because it's taking too long, but good to know and thanks!
Chris