File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Buffering on key up for ajax call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Buffering on key up for ajax call" Watch "Buffering on key up for ajax call" New topic

Buffering on key up for ajax call

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

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.


GenRocket - Experts at Building Test Data
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
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.

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

Thanks Eric. I'll give it a go.
subject: Buffering on key up for ajax call
Similar Threads
How to automate the login of an external website using AJAX or javascript
Timing issue with form submission and Ajax
Can AJAX helps me to do that
field group and onfocus
AJAX Frameworks that integrate with Struts