2012-10-22 52 views
0

我想調用一個json web服務,它是從sencha touch中部署在localhost(Tomcat)中的,但是我收到錯誤的請求響應,並且當我刪除content-type時,我收到不受支持的類型。請幫助爲我提供從sencha touch使用json服務的確切代碼。調用json webservice中的Sencha觸摸問題

下面是代碼,

Ext.Ajax.request({ 
     url:'../service/login.json', 
     headers: { 
     "Content-Type": "application/json" 
    }, 
     method:'POST', 
     params:{email:Ext.getCmp('login_field').getItems().items[0].getValue(),password:Ext.getCmp('login_field').getItems().items[1].getValue()}, 
     success:function(res,req){ 
      alert(res.reponseText); 
      var data = Ext.decode(res.responseText); 
      if(data.responseMessage){ 
       Ext.getCmp('login_field').getItems().items[0].reset(); 
       Ext.getCmp('login_field').getItems().items[1].reset(); 
       if(!Ext.getCmp('MainPanel')){ 
        Ext.Viewport.add({xtype: 'MainPanel'}); 
       } 
       Ext.getCmp('MainPanel').show({type:'slideIn',direction:'left'}); 
       Ext.getCmp('LoginPanel').hide(); 

      } 
    else{ 

      Ext.Msg.alert('Health Track','Invalid Login'); 
     } 

回答

0

這裏是我用我的應用程序的代碼。請務必在您的瀏覽器或所選工具中使用網絡檢查器,以查看是否正在處理該呼叫。

Ext.Ajax.request({ 
    url: http://www.example.com, 
    withCredentials: false, 
    useDefaultXhrHeader: false, 
    params: { 
     login: [email protected], 
     password: ******* 
    }, 

    callback: this.handleLoginCallback, 
    scope:this 
}); 
0

這取決於你的服務消耗&產生。如果你想命中正確的結束點(接受json),你必須指定'Content-Type':'application/json'。如果你想得到JSOn響應,你必須發送「Accept」頭文件,否則你將得到默認的類型(在大多數情況下是xml)。或者,您可以使用黑客技術,例如在URL中傳遞「_type = json」或在url中添加「.json」以獲取json響應。