我有以下情况:
$.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');
}
我正在使用延迟对象来执行一些方法链接。这一切都像一个魅力,但是我从 jqXHR 对象返回的 responseText 值a[2]
并b[2]
返回纯字符串。一种解决方案是只调用$.parseJSON()
字符串,但我想必须有更好的方法来做到这一点。
换句话说,我可以在使用$.getJSON()
with时从 jqXHR 对象获取直接 JSON 对象$when().then()
吗?