I have an AJAX request that looks like this:
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);
}
});
})();
This works great and the request repeats itself every 15 seconds. Now, I want to kill the request when I click a certain button (as shown). The compiler says that the fragment stats.abort() is not a function and continues the loop.
Any ideas?