我在使用jquery时遇到了很多关于307临时重定向
状态码的问题。
我有一个apache服务器,当需要时返回307。 307被正确地抛出(我可以通过firebug或wireshark跟踪看到),但我似乎无法触发重定向。
$.ajax({
url: someURL,
type: 'GET',
processData: false,
data: someData,
cache: true,
timeout: 5000,
statusCode: {
307: function() {
alert('307'); // this does NOT get called
}
},
error: function(request, status, error){
try {
console.log(request.getAllResponseHeaders());
}
catch (err) { }
},
success: function(data, textStatus, response){
try {
console.log(response.getAllResponseHeaders());
}
catch (err) { }
});
我想查看头部信息以便使用
getAllResponseHeaders()
方法进行重定向。这对于200状态码的情况很有效,但是在307的情况下无法触发(无论是在success
还是error
处理程序中)。当使用Firebug检查流量时,我注意到一个问题:重定向后立即向服务器发送了一个ajax
GET
请求,该请求的URL为重定向的URL!然而,这导致了失败。那么,是什么原因呢? 编辑: 我尝试过使用jquery 1.5.1和1.6.1。