Ajax JSON asynchronous request

Source: Internet
Author: User

functionajaxtest () {if(true) {$.ajaxsettings.async=false; varDatajson; $.getjson ("/universities",function(data) {Datajson=json.stringify (data); Console.log ("1>>>>>>>");        }); Console.log ("2>>>>>>>"); } console.log ("3>>>>>>>"); varsum = 1+2; Console.log ("4>>>>>>>" +sum);} No red part execution order is 2,3,4,1plus 0 Red part execution order is 1,2,3,41, appointment of successful patients with the patient on the day of their own identity card and the appointment of the Social Security Card (Medicare patients) or medical union card (self-financed patients) and received an appointment to reply to the message on time to the Registration fee window registered. First visit to Changhai hospital should go to the clinic first floor Hall 0-Register your personal information at Window No. 3rd and check in the registration procedure. Maternity registration must be made at your own expense. 2, after the successful appointment, for any reason can not be on time to visit the person, please advance through the website or dial 95169 for the cancellation procedures. If the appointment is cancelled 2 times, the appointment of Changhai Hospital is suspended within 180 days, but it does not affect the registration at the hospital site. $.getjson asynchronous request and synchronization requests look at a piece of code first: Copy the Code for(varj=0;j<24;j++) {(jQuery). Getjson (' log_analyze.php ', {r:math.random (), logid:logid,op:2,j:j},function(data) {if(data.success_agent) {varWidth=j*10; $("#up_time_loading"). Empty (). Append ("<div style=\" width: "+width+" px;height:10px;border:1px solid #333; Background-color: #333 \ "></div>"); }})} Copy the code This code means: request log_analyze.php, each request succeeds after the J plus 1, and then go to request. Open Firebug, you can see that these 24 data is asynchronous execution, so I log_analyze.php get the data is very chaotic, no rules, how to solve it? Add $.ajaxsettings.async prior to execution=false; (synchronous execution) copy code $.ajaxsettings.async=false;  for(varj=0;j<24;j++) {(jQuery). Getjson (' log_analyze.php ', {r:math.random (), logid:logid,op:2,j:j},function(data) {if(data.success_agent) {varWidth=j*10; $("#up_time_loading"). Empty (). Append ("<div style=\" width: "+width+" px;height:10px;border:1px solid #333; Background-color: #333 \ "></div>"); }})} Copy code to add a $.ajaxsettings.async before the for loop=false; Indicates synchronous execution, so that he will install the sequence of execution. The following is picked up from the Internet: Simultaneous execution of multiple $.getjson () The resolution of the problem of confusing data is added before execution $.ajaxsettings.async=false; (synchronous execution) immediately after executing your code back to $.ajaxsettings.async=true; (asynchronous execution) otherwise affects the code that needs to be executed asynchronously elsewhere. Example:$.ajaxsettings.async=false; $.getjson (URL, data,function(data) {}); $.getjson (URL, data,function(data) {}); $.getjson (URL, data,function(data) {}); $.ajaxsettings.async=true;

Ajax JSON asynchronous request

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.