Is there a way to cancel an ajax request when a button is clicked? I've tried some solutions I came across here, but none seem to work for me.
<button type="button" id="toStop">Stop</button>
Despite clicking the stop button, the ajax request does not abort.
function() {
var myajaxreq = $.ajax({
url: myurlhere,
type: 'GET',
async: true,
success: function(result) {
}
beforeSend: function () {
if(document.getElementById('toStop').clicked == true) {
myajaxreq.abort();
}
}
});
}