2012-06-08 71 views
0

我的Sencha Touch 2應用程序有幾個地方,它通過點擊按鈕發出AJAX請求。這是相當標準的東西:sencha touch ajax請求被調用兩次

console.log('Saving Billing Item at' + strURL); 
Ext.Ajax.request({ 
    url: strURL, 
    method: 'GET', 
    success: function (result, request) { 
     var resultJson = Ext.decode(result.responseText); 
     console.log('Response from Saving BillingItem:' + result.responseText); 
     data = Ext.decode(result.responseText); 
     if(data.ErrorMessage.indexOf("successfully") == -1) { 
      Ext.Msg.alert('Error!', 'Error saving Billing Item:' + data.ErrorMessage); 
     } else { 
      Ext.StoreMgr.get('BillingItemList').load(); 
      Ext.ComponentManager.get('MainMenu').animateActiveItem(23, { 
       type: 'slide', 
       direction: 'right' 
      }); //back to list 
     } 
     Ext.ComponentManager.get('BillingItemSaveButton').setDisabled(false); 
    }, 
    failure: function (result, request) { 
     Ext.Msg.alert('Error!', 'There was a problem while saving the Billing Item. Please check your input and try again.'); 
     Ext.ComponentManager.get('BillingItemSaveButton').setDisabled(false); 
    } 
}); 

然而,請求正在發送到服務器TWICE。

- 輕拍事件肯定只被解僱一次!

- 如果我手動瀏覽到strURL的URL,服務器端功能僅觸發一次,因此它不看來是任何服務器端。

但是(相同,除了URL)的應用程序的其他地方Ajax請求只火一次,我看不出有什麼區別!

我該如何去跟蹤它?

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
    System.out.println("In doGet"); 
    doPost(request,response); 
} 
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
    System.out.println("In doPost"); 
} 

結果爲:

In doPost 
In doGet 
In doPost 

我記得的東西是隻適用於EXTJS POST方法

+0

你是怎麼知道Ajax請求被觸發兩次的?控制檯上有任何o/p? –

+0

該服務在服務器上被調用兩次,每次該應用程序觸發該事件一次。 – SteveCav

+0

我也有同樣的問題。你有沒有找到解決辦法? – Kapil

回答

0

我可以把重定向的doPost從的doGet在我的服務,如重現行爲但我現在不記得它。話雖如此,你的servlet不會運行兩次,但同時運行doGet和doPost。

+0

很久以前,我從Sencha搬到了那裏,但感謝您的洞察力。希望其他人會發現它有幫助。 – SteveCav

相關問題