I have the following script:
$(document).ready(function(){
$('#input').keyup(function(){
sendValue($(this).val());
});
});
function sendValue(str){
$.post("ajax.php",{ sendValue: str },
function(data){
$('#display').html(data.returnValue);
}, "json");
}
The script is used in an instant search type scenario (like Google), so it is sending quite a few select requests to the server as the user types in the textbox (although I already use pconnect so there are no repeated databse connections).
It is quite a large database and every keystroke is sent as an AJAX request, so it ends up with a massive backlog of pending requests. I'd like it to stop/cancel all previous requests (if they haven't been send back) every time it sends a new request.
I've looked at xhr.abort()
but I'm pretty sure that will just stop any requests that haven't yet been sent (as opposed to telling the server to stop processing). This is probably OK, but I still don't know how to implement it in my code.