Javascript 使用多个参数和xhr时的Jquery$
Im在处理多个请求时使用$。请考虑下面的代码:Javascript 使用多个参数和xhr时的Jquery$,javascript,jquery,Javascript,Jquery,Im在处理多个请求时使用$。请考虑下面的代码: $.when( $.ajax({url: '/show/' + showId + '/details.json', type: 'GET', dataType: 'json', async: false}), $.ajax({url: '/show/' + showId + '/graphicAssets.json', type: 'GET', dataType: 'json', async: false}), $.ajax
$.when(
$.ajax({url: '/show/' + showId + '/details.json', type: 'GET', dataType: 'json', async: false}),
$.ajax({url: '/show/' + showId + '/graphicAssets.json', type: 'GET', dataType: 'json', async: false}),
$.ajax({url: '/graphicAssets/show/' + showId + '/files.json', type: 'GET', dataType: 'json', async: false}),
$.ajax({url: '/graphicAssets/show/types.json', type: 'GET', dataType: 'json', async: false}),
$.ajax({url: '/season/'+ showId +'/seasons.json', type: 'GET', dataType: 'json', async: false}),
$.ajax({url: '/freebie/' + showId + '/freebies.json', type: 'GET', dataType: 'json', async: false})
)
.then(function(showDetailsData, showGraphicAssetsData, showFilesData, showTypesData, showSeasonsData, showFreebieData, status, xhr) {
if (xhr.status == '302') location.reload();
// Rest of the code goes here
}
现在,我要做的是检查xhr对象的响应状态。结果未定义。我如何解决这个问题?非常感谢 如果将多个延迟传递给
$。当
时,处理程序将收到一个数组,其中包含解析每个延迟的结果。因此,在本例中,您将得到7个数组,每个数组包含数据、textStatus、jqXHR
因此,在您的情况下,正确的用法如下:
$.when(
$.ajax({url: '/show/' + showId + '/details.json', type: 'GET', dataType: 'json', async: false}),
$.ajax({url: '/show/' + showId + '/graphicAssets.json', type: 'GET', dataType: 'json', async: false}),
$.ajax({url: '/graphicAssets/show/' + showId + '/files.json', type: 'GET', dataType: 'json', async: false}),
$.ajax({url: '/graphicAssets/show/types.json', type: 'GET', dataType: 'json', async: false}),
$.ajax({url: '/season/'+ showId +'/seasons.json', type: 'GET', dataType: 'json', async: false}),
$.ajax({url: '/freebie/' + showId + '/freebies.json', type: 'GET', dataType: 'json', async: false})
)
.then(function(showDetailsData, showGraphicAssetsData, showFilesData, showTypesData, showSeasonsData, showFreebieData) {
if (showDetailsData[2].status == '302'
|| showGraphicAssetsData[2].status == '302'
... etc) location.reload();
// Rest of the code goes here
}
伟大的我正要回答我的问题,但你还是继续了。这是一封信。:)