I'm looking to chain multiple ajax requests, something along the lines of: get first JSON, if successful move on and get second JSON, if successful make a new object consisting of both JSON data.
// get first json
$.getJSON('http://www.json1.com').then(function(json1){
return json1
}).then(function(json1){
// get second json
$.getJSON('http://www.json2.com').then(function(json2){
var both = {}
both.one = json1
both.two = json2
return both
})
})
Should I be nesting .then
statements in each other? I'm not completely sure how to get the both
variable.