【问题标题】:Sencha Touch 2 How to get response headersSencha Touch 2 如何获取响应标头
【发布时间】:2013-06-21 01:31:27
【问题描述】:

我进行 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

我怎样才能获得 Location 标头?

当我尝试这样做时:

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

我有错误

无法读取未定义的属性“位置”

【问题讨论】:

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


    【解决方案1】:

    寻找解决方案:

    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);
                }
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-07
      • 2012-03-29
      • 2013-07-20
      • 2014-01-25
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      相关资源
      最近更新 更多