2

我有以下情况:

$.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()吗?

4

1 回答 1

1

猜猜没有更好的方法可以做到这一点。

于 2012-08-10T05:43:16.850 回答