2017-06-29 39 views
1

我有以下几点:

$.ajax(options) 
    .then(function (response) { 
     // success 
    }, function (response, a, b) { 
     // fail 
    }) 
    .always(function (output, status, xhr) { 
     // xhr is always null here 
    }); 

此前,xhr是可用的。我如何使用最新版本的jQuery访问它?

+0

你使用的是什么版本的jQuery? –

+0

@DeyvisonSouto 3.2.0 – SB2055

+0

你用任何东西了“于是”设置?我认为使用.then时回调的签名与使用旧学校$ .ajax调用相比是不同的。 – Culme

回答

1

您可以实现像jquery 3.2以下。一些以前的ajax方法已经被新版本的jquery弃用了。

var jqxhr = $.ajax("yourUrl") 
    .done(function() { 
    console.log("success"); 
    }) 
    .fail(function() { 
    console.log("error"); 
    }) 
    .always(function(xhr, status,output) { 
     console.log(xhr); 
    });