Sencha Touch 2如何获取响应标头

时间:2013-06-21 01:31:27

标签: ajax http-headers sencha-touch-2

我打电话给Ajax:

Ext.Ajax.request({
            url : 'http://apps.dhis2.org/demo/dhis-web-commons-security/login.action',
            callbackKey : 'callback',
            method : 'POST',
            params : {
                j_username : username,
                j_password : password
            },
            withCredentials : true,
            useDefaultXhrHeader : false,

            success : function(response) {
                var text = response.responseText;
                Ext.Msg.alert('Success', "Success login", Ext.emptyFn);
            },

            failure : function(response) {
                var text = response.responseText;
                Ext.Msg.alert('Error', "Failure login", Ext.emptyFn);
            }
        });

有回复标题:

Connection:Keep-Alive
Content-Length:0
Content-Type:text/plain
Date:Fri, 21 Jun 2013 01:23:51 GMT
Keep-Alive:timeout=5, max=100
Location:http://apps.dhis2.org/demo/
Set-Cookie:JSESSIONID=2E5D7C7235BE37150F1FE7B30EA0244D; Path=/demo/; HttpOnly
Vary:cookie

我可以获取位置标题吗?

当我尝试这样做时:

Ext.Ajax.on('requestcomplete',
        function(conn, response, options, eOpts) {
            var location = options.headers['Location'];
            Ext.Msg.alert('Success', location, Ext.emptyFn);
        }, this);

我有错误

无法阅读物业'位置'未定义的

1 个答案:

答案 0 :(得分:0)

寻找解决方案:

Ext.Ajax.request({
            url : 'http://apps.dhis2.org/demo/dhis-web-commons-security/login.action',
            method : 'POST',
            params : {
                j_username : username,
                j_password : password
            },
            withCredentials : true,
            useDefaultXhrHeader : false,

            success : function(response) {

                var Location = response.getResponseHeader('Location');
            },

            failure : function(response) {
                Ext.Msg.alert('Error', "Failure login", Ext.emptyFn);
            }
        });