How to implement AJAX delay send after idle to send Ajax request _ajax related

Source: Internet
Author: User

Most of the time, we all encounter the function of keyword search.

Our first idea, certainly, is to bind the response to the KeyUp event, and then will get the keyword to request an AJAX return response to the data processing

However, this time, if the KeyUp event is simply bound. So, every keystroke will send an AJAX request, which is obviously not what we want.

We hope to try to send Ajax requests after we have been free:

Therefore, we set the user to send this AJAX request after 1S without tapping the keyboard

Copy Code code as follows:

var timeout;
onkeyup = function () {
Cleartimeout (timeout);
Timeout = settimeout (function () {
Ajax request
}, 1000);
}

Of course, you can use another idea:

To block out Ajax requests:
Copy Code code as follows:

if (request) {
Request.abort ();
}
Request = $.ajax ()

But this Ajax request is best blocked before the Ajax issue

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.