Loading waiting before ajax returns data, ajaxloading
Pie Chart
Click the event (<a sceneid = "@ scene. ID "href =" javascript: void (0) "onclick =" build (this) "> Generate </a>)
Call the following method:
Function build (sender) {var jqSender =$ (sender); var sceneid = jqSender. attr ('sceneid'); $. ajax ({type: 'post', url: "Follow/UpdateUrl", data: {sceneid: sceneid}, beforeSend: function () {jqSender. hide (). after ('') ;}, success: function (data) {// obtain the td tag $ ('tbody tr [id = '+ sceneid +'] td.wxurl-col'}.html (data. QRUrl); $ ('tbody tr [id = '+ sceneid +'] td.localkey-col').html (data. localKey); // hide the generate button and insert the image var localkey = data. localKey; jqSender. after ('');}, complete: function () {$ ('# load '). remove ();}});}Ajax
The background page will not be written. The url is configured with the path passed to the background. The most important thing is
BeforeSend: function () {jqSender. hide (). after (' ');},
This should take into account the characteristics of ajax asynchronous requests. When ajax is executed to a url, a thread will jump to the background for execution,
The browser will add a thread (I don't know if this is the standard) to continue executing the subsequent Program, to success: function (data) to pause waiting for the returned data to be successful in the background.
In this way, the inserted image in before is equivalent to a loading. After the data is successfully returned, remove the image in before and write it in the complete: function () statement.
The background processing process is like this: first, an http GET request gets the access_token of the public platform, and then uses the http POST request to obtain the ticket in exchange for the QR code.
Then, use the WebClient method to download the requested QR code to the local storage, and then add, query, modify, and display the QR code on the web page.
In such a large segment, loading has enough time to display it. If the time is short, you can check whether a time has been defined on the Internet, so that loading can be fully displayed, so as not to be abrupt.
Note: This article is for reference only. It also has many flaws. The most important thing is not code, but logic.