tholo tholo - 1 year ago 79
AngularJS Question

Get several JSON files in one function

The structure of JSON link is as follows:

Now I need to get several JSON link files and the only thing that changes is the number part in the link above. Let's say it ranges from 10 to 40, so the first one looks like this:

and the second one looks like this

and so on until it reaches number 40.

Is there a way I can get it all in one function. I've tried this:

var nmr = function({for(nmr=10;nmr<40;nmr++)});

var json = ''+nmr+'rest-of-the-link.json';

but it won't work.

Is there a way to achieve this?

Please note that I have't put the "http" part as the SO automatically links it.


Answer Source

you can build array like this

var links = [];
for(var i=2005;i<2015.length;i++){
//now make your request for each link

another example

var requested = 0;
   function startLoading(){
     if(requested==2015)return alert("all files loaded");
 function makeRequest(url){
     //the body of request
     //if response is ready make what you want for it and go next
     // and startLoading(); to go to the next link

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download