Reputation: 4147
I have an ajax call that has 2 objects being brought back that has other objects contained within it. I am trying to split off the first object and string together all of the objects into a string array.
function first(){
$.ajax({
url: '/main/sub',
data: { var1: var1, var2: var2, var3:var3 }
}).done(function(results){
if (results != ""){
var test = populateSource(JSON.parse(results)); // this gets everything back
}
}
}
So the variables that get brought back are Apps and SubApps in which Apps contains 10 objects that they each have objects within it.
For example, it returns:
Apps: Array [100] SubApps: Array [3]
If you click on Array[100] it returns: 0: Object 1: Object... with the data inside each object
I need a variable to split off the Apps array and just show the data inside like:
"[{"cycle":1, "cycle2":2, ...}]"
Upvotes: 0
Views: 1803
Reputation: 2952
for(i = 0; i <= results.length; i++) {
if(results.length > i) {
var data1 = results[i].var1;
var data2 = results[i].var2;
}
}
that's a basic for loop to get the data split, you just need to match the values to the values you receive back.
P.S. put this in the .done and not outside of it.
Upvotes: 1