File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 JavaScript Promises Essentials this week in the JavaScript 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
Author

Buffering on key up for ajax call

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Thanks Eric. I'll give it a go.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Buffering on key up for ajax call