I have a jQuery dialog box that opens and then an AJAX call is made. I would like to make it so that if the dialog box is closed or the cancel button is pressed the AJAX call is canceled and its callback function is not called. I can think of some ways to do it with a variable like so:
function doStuff(){
var doCallback = true;
$('#dialog').dialog({
title: 'Dialog Title',
modal: true,
buttons: {
Cancel: function() {
doCallback = false;
doSomethingElse();
}
}
});
$.get('url/url/url', function(data){
if(doCallback){
doTheSuccessThing(data);
}
});
}
But, somehow that feels dirty to me and it doesn't actually stop the AJAX call from completing. Is there a built-in way to cancel an AJAX call in progress?