When I was working on a project, I used a table control and its data was asynchronously loaded. I used some business processing in the function of Binding data to this table. When I ran the page, I used a browser to place a breakpoint tracking on the place where I wrote business processing. It was actually executed. when it could be finally displayed, its processing was overwritten. I was wondering, at that time, I also knew that the table binding function had a problem, but it was time-consuming. Its functions were encapsulated and not tracked in detail, this is a clumsy method, but it is also an effective method.
Later, I checked the document and found some information. In fact, the principle should be as follows:
By default, all requests are asynchronous requests. To send a synchronization request, set this option to false. Note: The synchronous request locks the browser. Other operations can be performed only after the request is completed.
View code
1 VaR Temp; 2 $. Ajax ({ 3 Async: False , 4 Type: "Post" , 5 URL: defaultpostdata. url, 6 Datatype: 'json' , 7 Success: Function (Data ){ 8 Temp = Data; 9 } 10 }); 11 Alert (temp );
This Ajax request is a synchronous request. Alert (temp) will not execute until no return value is returned.
If async is set to true, the Ajax statement is executed directly without waiting for the results returned by the Ajax request.