This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Buffering on key up for ajax call" Watch "Buffering on key up for ajax call" New topic
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
    
    6
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Buffering on key up for ajax call
 
Similar Threads
field group and onfocus
How to automate the login of an external website using AJAX or javascript
Can AJAX helps me to do that
Timing issue with form submission and Ajax
AJAX Frameworks that integrate with Struts