You need to implement this behavior so that when a new letter is entered in a field, 1 second will pass and a certain method will be executed. A timer is needed for this, but when letters are quickly entered (for example, 3 letters per second), the timers are queued and then executed sequentially.
It is required that there should be a timer that, with each new letter entered, will be restarted, but if the letters were not entered within 1 second. then the desired method was run.
Here is my code:
var isTimerWork = false; var timer = null; $('#SearchString').on("keyup", function() { if ($('#SearchString').val().length >= 2 && !IsExtSearch) { if (timer != null) clearTimeout(timer); timer = setTimeout(isTimerWork = true, 1000); while (!isTimerWork); GetAutoCompleteData($('#SearchString').val()); } in my case, it turns out that a new timer is created every time.
(!isTimerWork);if I didn’t immediately assigntrueto this variable before it - Grundy