| Author |
Buffering on key up for ajax call
|
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
I have a form where two fields will be validated to be unique on posting of the form. I decided to validate these two fields as they are typed using ajax. What I have works fine, but I don't like the number of hits the server takes when the user is typing in the string. What I would prefer is if there was a way I could somehow wait for the user to stop typing or pause typing before sending the ajax call. I don't want to use on blur. I like the on key up approach, I just would like it to be smarter in the way my function handles all the key strokes. I hope this makes sense. Thanks.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
I like the idea of using setTimeouts to hold a pending request (Ajax call). If another key action takes place cancel it out. After X number of cancels, I would make a request if one has not been made and just take note of new keystrokes. The setTimeout will make the call to server after it fires. I would avoid the abort() style that some people like to implement. You could also do sort of an autocomplete type ofthing under the covers, bring back results if it is less than Y possible combinations and use that as sort of a cache. Compare against them instead of hitting the server. Eric
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
Thanks Eric. I'll give it a go.
|
 |
 |
|
|
subject: Buffering on key up for ajax call
|
|
|