jquery ajax Submission "Load in" prompt processing method _ajax

Source: Internet
Author: User

Method 1: Use the Ajaxstart method to define a global "load ..." The prompt

$ (function () {
$ ("#loading"). Ajaxstart (function () {
$ (this). html. ("});
$ ("#loading"). Ajaxsuccess (function () {
$ (this). html. ("");
$ (this). empty (); or clear it directly.
});

});

<div id= "Loading" ></div>

Attention:

All of the AJAX submissions will trigger the Ajaxstart event, which will be defined in the

<div id= "Loading" ></div>

The location shows "Loading ..." "Icon (of course you can also define text, but a load of the picture is more good-looking);

-------But it must be noted that at the same time to define a good ajaxsuccess event, Ajax submitted successfully after the icon to hide ...

Special tips:

When using Ajaxstart or ajaxsuccess events, the equivalent of defining a global display "load ..." "The location of all AJAX submissions" Loading ... "Icon is always displayed in one place ....

Method 2: In the Ajax method, define any position shown in the "Load ..." The prompt

$ (' #ajax_test2 '). Click (function () {
$.ajax ({
URL----URL path, depending on what you need,
Type: ' Post ',
Data: ' NAME=ZXCVB ',
timeout:15000,
Beforesend:function (XMLHttpRequest) {
Alert (' Remote call begins ... ');
$ ("#loading"). html. ("},
Success:function (data,textstatus) {
Alert (' Start callback, state text value: ' +textstatus+ ' returns data: ' +data ');
$ ("#loading"). empty ();
},
Complete:function (xmlhttprequest,textstatus) {
Alert (' Remote call succeeded, status text value: ' +textstatus ');
$ ("#loading"). empty ();
},
Error:function (Xmlhttprequest,textstatus,errorthrown) {
Alert (' Error ... Status text value: ' +textstatus+ ' exception information: ' +errorthrown ';
$ ("#loading"). empty ();
}
});
});

< input type.= "button" id= "Ajax_test2" value= "ajax Mode" >
<div id= "Loading" ></div>

Obviously, when Beforesend, the "Load ..." is displayed at the specified location. "Icon, after the error, complete, success the icon removed ....

Attention:

When there are multiple AJAX submissions on a page, it is recommended that the second approach be used, because "Loading ... "icon can be displayed in any location you need to refresh ... This is its advantage: freedom ....

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.