2013-06-21 24 views
0

我讓Ajax調用:煎茶觸摸2如何獲得響應頭

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

我有錯誤

無法讀取未定義

回答

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