jquery Ajax Request way and prompt the user is processing please wait _jquery

Source: Internet
Author: User

For the first time using $.ajax (), I did not differentiate between Ajax asynchronous requests and synchronization requests, just beginning to use sync requests, and then many problems, especially in terms of experience.
Asynchronous and synchronous:
synchronization means that the execution of a program to perform the next paragraph, which is blocking mode, its performance on the Web page phenomenon is-the browser will lock the page (that is, the so-called page suspended animation state), the user can not operate other, must wait for the current request to return data. In the asynchronous way, the page does not appear to be suspended.
enhance the user experience degree:
when the user submits the data waiting for the page to return the results will take time, and sometimes the waiting time is longer, in order to improve the user experience, we usually give "processing, please wait a moment!" "Such a hint. We can do this by setting the parameter Beforesend () under $.ajax ().
eg
HTML Key Code

<div id= "Warning" ></div>

Key code in JS file

$.ajax (function () {
...
)
Some parameters are omitted, and only the async and Beforesend
async:false,//sync requests are given, by default asynchronous (True)
beforesend:function () {
$ (' # Warning '). Text (' Processing, please wait a moment! ');
}
});

Note that if you set the Async:false according to sync, $ (' #warning '). Text (' Processing, please wait! '); no effect at all in Web pages, if $ (' #warning '). Text (' Processing, please wait! '); Switch to alert (' test ') and see the pop-up box immediately before sending the request, which means that beforesend: is executed, but is replaced with something else such as $ (' #warning '). Text (' Processing, please wait! '); No prompts appear when the request sends back results. On this question, I was puzzled for a long time, I still do not know what the problem is.
To change the sync request to an asynchronous request, the problem is gone.

Beforesend:function () {
$ (' #warning '). Text (' Processing, please wait! ');
}

will be executed immediately.

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.