Continue Ajax long polling solution-recursion

Source: Internet
Author: User

If you use for, there is a situation where the execution of Ajax will be greater than the execution of other actions, then such a piece of code will not be implemented

for (Var i=0;i<20;i++) {

Console.log (' Hello ')

$.ajax (...)

}

What do we do?

Recursion, a lot of old programmers are doing this, so the code:

Currentindex = 0; functionAjax () {if(currentindex>=20) {           return; }      varURL =' URL ';      Console.log (i); $.ajax ({type:' Get ', Url:url, DataType:"JSON", Async:false, Cache:true, Success:function(JSON) {Currentindex++; Console.log ("Test");Ajax (); }, Error:function(data) {Console.log ("Error ..."); Currentindex++;          Ajax ();  }      }); }  

Three major steps to solve the problem: 1. I want to, 2. Can't think of it, go online to find it, 3. Can't find, put the computer back to the system, and then submit the resignation, and then say goodbye to it. ^-^

Continue Ajax long polling solution-recursion

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.