• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Buffering on key up for ajax call

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Eric. I'll give it a go.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic