I am attempting to stop the previous AJAX request when a new keyup
event fires. The patten is like this:
- User enters
A
, my code will submit the form using AJAX with atest_value
ofA
. - When user enters
B
I want to stop the AJAX request from the first step and make a new request withtest_value
ofAB
.
<input type="text" id="xxx" onkeyup="test_fn(this.value)" autocomplete="off">
<div id="loading" style="display: none;">please wait.....</div>
<span id="myplace_test"></span>
<form id="test_fid" method="POST" action="" style="display: none;">
<input type="text" name="test_value" id="test_value">
</form>
function test_fn(val) {
document.getElementById("loading").style.display = "block";
document.getElementById("test_value").value = val;
$.ajax({
url: "test.php",
type: "POST",
data: $('#test_fid').serialize(),
cache: false,
success: function(data) {
$('#myplace_test').html(data);
document.getElementById("loading").style.display = "none";
}
});
}