I've got the following situation:
$.when(jsonCall1(),jsonCall2())
.then(function(a,b){
var json1 = a[2].responseText;
var json2 = b[2].responseText;
--- Do some stuff with these json responses ---
})
.fail(function(){
console.log( 'failed requests...');
});
}
var jsonCall1 = function(){
return $.getJSON('http://myURL/1');
}
var jsonCall2 = function(){
return $.getJSON('http://myURL/2');
}
I'm using the deferred objects to do some chaining of methods. This all works like a charm, but the responseText values i get back from the jqXHR object a[2]
and b[2]
return plain strings. One solution is to just call $.parseJSON()
on the strings, but I guess there must be a better way to do this.
In other words, can I get a direct JSON object from the jqXHR object when using $.getJSON()
with $when().then()
?
Guess that there is no better way of doing this.