App*_*pps 35 jquery httpresponse
当我们使用jQuery触发ajax请求时,我们如何访问响应头?我根据某些网站提供的建议尝试使用以下代码.但是xhr对象将变为空.我xhr在这种情况下看到了一个对象.但它没有访问响应头的方法.
function SampleMethod(){
var savedThis=this;
this.invokeProcedure=function(procedurePath){
$.ajax({
type: "GET",
url: procedurePath,
dataType: "json",
success: function(data,status,xhr){savedThis.resultSetHandler(data,status,xhr);}
});
}
this.resultSetHandler=function(data,status,xhrObj){
//Handle the result
}
this.errorHandler=function(args){
//Handle the result
}
}
var sampleObj=new SampleMethod();
sampleObj.invokeProcedure('url');
Run Code Online (Sandbox Code Playgroud)
odu*_*ont 73
为了向后兼容XMLHttpRequest,jqXHR对象将公开以下属性和方法:getAllResponseHeaders() 和 getResponseHeader().来自$ .ajax()doc:http://api.jquery.com/jQuery.ajax/
对于jQuery> 1.3
success: function(res, status, xhr) {
alert(xhr.getResponseHeader("myHeader"));
}
Run Code Online (Sandbox Code Playgroud)