I am trying to cancel all remaining AJAX requests if the length of an input field is empty. However, I am seeing this error:
Uncaught TypeError: Cannot read property 'abort' of undefined
$("input#enter").keyup(function() {
if(this.value.length < 1) {
$("#display").empty();
request.abort(); // <--- this line
}else{
var request = $.ajax({
type: "POST",
url: "getdata.php",
data: "title=" + this.value,
success: function(data) {
$("#display").empty();
$("#display").html(data);
}
});
}
});
This is where I saw a similar example and they used request.abort()
: Stop all active ajax requests in jQuery