AJAX latest request
AJAX latest request
Hello, I am writing an AJAX autocomplete function with jquery (and CouchDB + evently).
I have a Input field and if a user types a text, i get an autocomplete sugest from the DB.
The problem is, that because of CouchDB evently I have some restrictions.
Every time, the user types a key, the following function is call:
- function(e) {
var searchString = $(this).val();
var widget = $(this);
$.ajax({
url : 'http://xyz"' + searchString,
success : function(req) {
var resp = $.parseJSON(req.responseText);
widget.trigger("autocompleteResult", resp);
}
});
}
My problem:
If the user types faster than the request is finished, there is a possibility, that the older request takes longer, than the latest one and he gets an old suggestion.
Is there any possibility within this function(e), to trigger the event only with the new result?
Best regards!