How to start an AJAX request at a significant pause during user inputting using Jquery?

Basically, you want to initiate your AJAX call some time after the user's last input. If you're using a textbox, you can do this by handling the keyup event and scheduling your AJAX call using setTimeout() At the start of your event handler, you can check for a scheduled call and cancel it (since the user started typing again): var ajaxCallTimeoutID = null; function doAjax() { // Do AJAX call here... } $('#myTextbox'). Keyup(function(ev) { if (ajaxCallTimeoutID!

= null) clearTimeout(ajaxCallTimeoutID); ajaxCallTimeoutID = setTimeout(doAjax, 300); }) If you want to react to user input across the entire form, then you just have to expand the events your handler handles. You would probably want to handle keyup for text boxes, textareas and select elements change for select elements, and probably focus on everything.

Basically, you want to initiate your AJAX call some time after the user's last input. If you're using a textbox, you can do this by handling the keyup event and scheduling your AJAX call using setTimeout(). At the start of your event handler, you can check for a scheduled call and cancel it (since the user started typing again): var ajaxCallTimeoutID = null; function doAjax() { // Do AJAX call here... } $('#myTextbox').

Keyup(function(ev) { if (ajaxCallTimeoutID! = null) clearTimeout(ajaxCallTimeoutID); ajaxCallTimeoutID = setTimeout(doAjax, 300); }); If you want to react to user input across the entire form, then you just have to expand the events your handler handles. You would probably want to handle keyup for text boxes, textareas and select elements, change for select elements, and probably focus on everything.

The Ajax function is executed each time a new letter is entered. – Steven Dec 28 '09 at 6:10 The 2nd parameter to setTimeout() specifies the delay in milliseconds.My example sets it to 300ms, so it happens pretty quickly (good for autocomplete lookups, maybe not good for your purpose). Try changing that value to 3000 (3 seconds) or so.

– Annabelle Dec 28 '09 at 20:42.

I use the following function, it basically executes a callback after the user has stopped typing for a specified amount of time: var typewatch = function(){ var timer = 0; return function(callback, ms){ clearTimeout (timer); timer = setTimeout(callback, ms); } }(); Usage: $('input'). Keyup(function() { typewatch(function(){ alert('Time elapsed, make Ajax request...'); }, 1000 ); // wait one second }); You could give a look to the jQuery Typewatch plugin for something more complex.

Simply start a timer for a reasonable delay: var delaying = false; function doAjax() { // ... begin Ajax delaying = false; } $('#myTextbox'). Keyup(function(ev) { if (!delaying) { delaying = true; setInterval(doAjax, 3000); } }).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions