E
E
EvgMul2016-12-07 14:55:01
JavaScript
EvgMul, 2016-12-07 14:55:01

How to run a double js ajax request loop?

Hello. I have the following problem.
You need to parse an XML file.

I parse it with something like this function (I omitted some details, such as filling in the progress bar, so that the essence is clearer):

function parsing(iterationObject, numberObjects) {

  return $.ajax({
    url: "parse.php",
    method: "GET",
    success: function(data) {
      
      if (iterationObject <= numberObjects) {
        iterationObject++;
        parsing(iterationObject, numberObjects);
      }
    }
  });
}


At the moment, the task has changed somewhat. Each object may or may not contain a number of links to images to be uploaded.

Those. now we need to implement the algorithm:
1. Run a loop through the objects
2. Check for links to images 3. If there are
links, run a loop to upload images one at a time (to implement the second progress bar for images)

and it's nice to implement such a thing. Tell me please.
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew K, 2016-12-07
@1px

async: true
By default, all requests are sent asynchronously (i.e. true). If you want to send requests synchronously, set to false. Synchronous requests may block the browser for the duration of the request.

U
ukoHka, 2016-12-07
@ukoHka

Try to write

function parsing(iterationObject, numberObjects) {
  return $.ajax({
    url: "parse.php",
    method: "GET",
    success: function(data) {
      if (data.hasImages){
parsingImages(image, numberImages, iterationObject );
} else 
      if (iterationObject <= numberObjects) {
        iterationObject++;
        parsing(iterationObject, numberObjects);
      }
    }
  });
}

In the parsingImages() function, you will process images using the same recursion.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question