doing multiple ajax request but response always the same

Viewed 53

I am trying to make multiple request to store different profiles from a website on one array. But on safari i keep getting the same profile as the response for my requests . on the other browsers is working fine.

...

for(let i=0;i<12;i++){   
    $.ajax({
        url: "https://randomuser.me/api",
      }).done(function(data) {
        profiles.push(data);
      });
}

...

this is what i am getting but every profile should be different [1]: https://i.stack.imgur.com/WnfzW.png

what can i do to solve this

1 Answers

If it works on all other browsers it might be a caching issue.

You don't need to make 12 calls to the API you can just fetch the amount you need by changing the results in the API call.

Here is an example that prints 12 names:

$.ajax({
    url: "https://randomuser.me/api?results=12",
}).done(function(data) {
    data.results.forEach(user => {
        console.log(user.name.first);
    });
});
Related