I have a problem with the code below.
Basically im implementing a polling mechanism, but when it is supposed to stop polling it just continues to poll. Polling infinite.
Is there any other way to force it to stop?
The function SearchPoll is only called once.
function SearchPoll(){
var i = setInterval(function ()
{
var url = "Search.aspx?polling=true";
$.ajax(
{
url: url,
success: function (data)
{
clearInterval(i);
},
error: function ()
{
clearInterval(i);
}
});
}, 1000);
}
If you want to kill all requests you need to work with the XMLHTTPRequest object returned from $.ajax. Here is an example: