Hello Derek,
When I type in an amount of 200, the ajax onkeyup event shows wrong totals because ajax does asynch handling.
In firebug, fisrt I see 200 then 2 and then 20.
When I type slow I don’t have a problem,
Can you write some code that wil handle the call synchrone
like
Example = {
interval : 1000,
lastKeypress : null,
interceptKeypress : function() {
this.lastKeypress = new Date().getTime();
var that = this;
setTimeout(function() {
var currentTime = new Date().getTime();
if(currentTime - that.lastKeypress > that.interval) {
that.sendRequest();
}
}, that.interval + 100);
},
sendRequest : function() {
//Perform xhr request
}
}
The Example.interceptKeypress() method now becomes what you tie the keyup event of your text input to instead of going straight to the Example.sendRequest() method. The current time is recorded, and then Example.sendRequest() is queued up using setTimeout() and a closure to handle scoping and ensure that enough time has passed since the last keyup event (100 ms is added to the current time as a buffer).
Hope you can help thanks in advance.