2

I start long polling in JavaScript:

getNewMessagesLong();

function getNewMessagesLong() {
$.ajax({
 type: 'POST',
 url: "listenMessageLong",
 dataType: 'json',
 success: function(data) {
        alert("success: " + data);
   }, complete: poll, timeout: 30000 });
 };

So how can I stop this polling after start?

1 Answers1

1

I think this way gonna be right to slve this problem:

var $request;

function getNewMessagesLong() {
$request = $.ajax({
 type: 'POST',
 url: "listenMessageLong",
 dataType: 'json',
 success: function(data) {
        alert("success: " + data);
   }, complete: poll, timeout: 30000 });
};

And if you wanna to stop polling:

if ($request != null){ 
        $request.abort();
        $request = null;
    }