Eine sich wiederholende AJAX-Anfrage beenden

Ich habe eine AJAX-Anfrage, die so aussieht:

var statistics = "link-to-a-JSONP";

function team_stats(json) {
   alert(json);
}

(function stats() {
        $.ajax({
            type: 'GET',
            url: statistics + '?callback=jsonp',
            crossDomain: true,
            dataType: 'jsonp',
            jsonpCallback: 'team_stats',
            jsonp: 'callback',
            data: {},
            success: function(data) {
              var test += '<div>' + data + '</div>';
              $(".content").append(test);

              /* a close button that closes the tab and kills the request */
              $("#closeStats").on("click", function() {
                    stats.abort();
                });
            },
            complete: function() {
              setTimeout(stats, 15000);
            }
       });
})();

Das funktioniert super und die Anfrage wiederholt sich alle 15 Sekunden. Jetzt möchte ich die Anfrage beenden, wenn ich auf eine bestimmte Schaltfläche klicke (siehe Abbildung). Der Compiler sagt, dass das Fragment stats.abort () keine Funktion ist und setzt die Schleife fort.

Irgendwelche Ideen

Antworten auf die Frage(2)

Ihre Antwort auf die Frage