If you do this on keydown and key up then it will only stop the call when
they have a key pressed.  My suggestion is to set the var on keyup use
setTimeout to call a function one second after the keyup to set the var back
to true.  Create another setTimeout on the keyup for 1.1 seconds that checks
the state of the var and makes the call if it is ready.  Although that may
have some timing issues too.  Good luck.  Give it a little more thought and
I think you can come up with something.

Amos

On Thu, Jan 14, 2010 at 7:57 PM, mslade <markandrewsl...@gmail.com> wrote:

> Here's what I would do.  Hope this makes sense:
>
>  [0] On key down, set some global state variable to true.
>
>  [1] On key up, set the state variable to false.
>
>  [1a] Then use setTimeout() to have it call a new function in 1 second
> (adjust for usability).
>
>  [2] Your new function will look to to see if the state variable from
> [1] is still false.  If it is false, do your ajax.  If it is not
> false, do nothing.
>
> On Jan 14, 8:20 pm, Info <i...@vglservices.com> wrote:
> > Hi There,
> > I have some code (below) that does an ajax call on keyup of a form
> > field. It works great.....but I really want to pause the call for 1
> > sec after they do the keyup to allow them to put in some text. Is
> > there a way to take this code and do that?
> >
> > $(document).ready(function(){
> >         $('#search').keyup(function() {
> >                 var searchVal = $('#search').val();
> >                 $.ajax({
> >                         type: 'GET',
> >                         url: 'qryget_customers.php',
> >                         data: 'search=' + searchVal,
> >                         dataType: 'html',
> >                         beforeSend: function() {
> >                                 $('#search_slips').html('<img
> src="../common/images/ajax-
> > loader.gif" alt="loading..." />');
> >                         },
> >                         success: function(response) {
> >                                 $('#search_slips').html(response);
> >                         }
> >                 });
> >         });
> >
> > });
>



-- 
Amos King
http://dirtyInformation.com
http://github.com/Adkron
--
Looking for something to do? Visit http://ImThere.com

Reply via email to