我正在尝试调试对API的jQuery调用,但xhr.responseText
似乎总是未定义。我需要对此代码进行哪些更改才能查看错误的详细信息?
jQuery.ajax({
url: 'http://fusion-api-user.dev/api/v1/user/authorise/' + currentVideoItem.id + '/play',
async: async,
beforeSend: function(xhr){
xhr.setRequestHeader('X-Forwarded-Host', 'fusion.dev');
},
xhrFields: {
withCredentials: true
},
success: function (res, status, xhr) {
currentVideoItem.authModule.playWithToken(xhr.getResponseHeader("X-Token"), "ais");
alert('xhr: ' + xhr);
alert('token:' + xhr.getResponseHeader('X-Token'));
jQuery(currentVideoItem.parentContainer).trigger('video-authorized', [{
id: currentVideoItem.id
}]);
},
error: function(xhr, status) {
alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
alert("responseText: " + xhr.responseText);
jQuery(window).trigger('countdown-session-ended', [{
name: 'video',
trigger: 'authorizePlayError'
}]);
}
});
答案 0 :(得分:0)
我通过添加回调函数并在成功函数中调用它来解决这个问题,如下所示:
success: function (response) {
//
callback(response);
//
},