ExtJS的4.2.1:无法检索时Ext.ajax.request回调HTTP响应头 [英] ExtJS 4.2.1: Cannot retrieve HTTP Response headers upon Ext.ajax.request callback

查看:141
本文介绍了ExtJS的4.2.1:无法检索时Ext.ajax.request回调HTTP响应头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读经Ext.ajax.request未来响应的头。

I'm trying to read the headers of the coming response upon Ext.ajax.request.

这是code:

Ext.Ajax.request({ url: 'http://localhost:3000/v0.1/login' ,
    method: 'POST',
    scope:this,
    jsonData: {"_username":username,"_userpwd":password},
    success: function(responseObject){
        var headers = responseObject.getAllResponseHeaders();
        console.info(headers );
        Ext.destroy(Ext.ComponentQuery.query('#loginWindow'));
        this.application.getController('SiteViewController').showView();
    },
    failure: function(responseObject){
        alert(responseObject.status);
    }
    });

但是,它印在控制台中唯一的标题是:

But the only header that it is printed out in console is:

Object {content-type: "application/json; charset=utf-8"} 

所有其它头被丢失,但他们是present在Chrome检查!

All the other headers are missing, but they are present in the chrome inspector!!!

我在想什么?谢谢

推荐答案

由于你可能做一个跨域请求,你只会有头由服务器明确地暴露出来。同样域的请求揭露所有的标题。

Because you're probably doing a cross-domain request, you will only have headers explicitly exposed by the server. Same domain requests expose all the headers.

在服务器端,您要添加的头访问控制 - 暴露 - 头你要揭露头,由昏迷分开的完整清单。在PHP中是这样的:

On the server side you have to add the header "Access-Control-Expose-Headers" with the exhaustive list of headers you want to expose, separated by a coma. In php it would look like this:

header("Access-Control-Expose-Headers: Content-length, X-My-Own-Header");

标头将通过 responseObject.getAllResponseHeaders()或类似 responseObject.getResponseHeader('内涵式')

有关跨域请求和头的详细信息: http://www.html5rocks.com / EN /教程/ CORS /

More information about cross-domain requests and headers: http://www.html5rocks.com/en/tutorials/cors/

PS:Ace.Yin有正确的答案,但我没有足够的声誉简评

PS: Ace.Yin had the right answer, but I don't have enough reputation to simply comment.

这篇关于ExtJS的4.2.1:无法检索时Ext.ajax.request回调HTTP响应头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆