An answer to a short blank page in AJAX data loading

Source: Internet
Author: User
Tags blank page
In the project with Ajax to get data asynchronously sometimes because of data problems or network problems, the page has been shown blank, and now load the picture to transition this state, specific example code through this article to learn together, hope to help everyone.


<script> $ (function () {$.ajax ({URL: ',///File address link for Interface dataType: ' JSON ', type: ' POST ', befores End:function () {$ (' #loading '). HTML ("<p style=\" color: #999; font-size:14px\ "> Load, please ......</p> later")//Data send process first load picture}, Error:fu        Nction (msg) {//Data read failed display Znodes=data.responsejson;      Alert ("Sorry, data acquisition failed, please contact Administrator");  }, Success:function (msg) {//Data read successfully and displays the data list $ (' #loading '). FadeOut (1000);        The picture shows the time; var ul = ""; for (var i= 0;i<msg.legth;i++) {//Data list lines ul + = "<li class= ' list ' ><a href= ' php/phparticle.php?art=" +msg I [' id ']+ ' class= ' widget-list-link ' > ' + msg[i][' title ']+ ' <i class= ' more-mark ' > ' + ' >> ' + ' </i><        /a></li> ";      } $ ("#list"). HTML (UL);      }, Error:function () {////Console.log ("link Error") on failure;  }    }); });</script>

Data is displayed in the load state

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.