Ajax request examples and precautions of jquery
Recently, many people have asked me how to use ajax, how to access the background, how to obtain the data page display, and write a simple ajax access: $. ajax ({url: ctx + "/meeting/getMeetingRoomMap", // request background address type: "get", // Request Method cache: false, // control whether to cache data (the default value is false FOR post requests, and the value of get requests is true, which may easily cause page data cache problems) async: false, // control synchronous or asynchronous data: {scheduleDate: scheduleDate}, // input parameter success: function (data) {if (data! = Null & data! = "") {$ (". ShowMessage ").html (data); // callback function for retrieving data from the background }}); two notes for ajax: 1. cache attribute. The default value is true, this is the question of whether the page needs to be cached. Many people say that the value has been modified clearly. Why is the value not changed? It is because this attribute is being made strange and can be set to false during request. 2. async attribute, the default value is true. This attribute determines whether your ajax request is synchronous or asynchronous. If this attribute is not set to false, js will execute a row in the same way as the background code. The default value is true, asynchronous processing may result in the execution of your next JavaScript code before ajax execution is complete. In fact, ajax is quite simple. It requests the background to obtain data callback, after the page is displayed, we recommend that you use it quickly --------------------------------------------test.html <a href = "javascript: void (0)" onmouseover = "testAsync ()"> asy. js function testAsync () {var temp; $. ajax ({async: false, type: "GET", url: 'tet. php ', complete: function (msg) {alert ('complete') ;}, success: function (data) {al Ert ('success'); temp = data ;}}); alert (temp + 'end');} tet. php <? Php echo "here is html code"; sleep (5);?> Async: false (the default value is true). If the preceding value is false, the Ajax request in testAsync () method will lock the entire browser, only tet. other operations can be performed only after php Execution is complete. When async: true, ajax requests are asynchronous. However, there is a problem: ajax requests in testAsync () and subsequent operations are executed asynchronously, so when tet. php may have executed the following operations after the ajax request, such as alert (temp + 'end'). However, the temp data is assigned a value after the ajax request success. The result is null in the output.