Sencha Touch Ajax 请求调用了两次

sencha touch ajax request called twice

本文关键字:两次 Touch Ajax 请求 调用 Sencha      更新时间:2023-09-26

我的Sencha Touch 2应用程序有几个地方,它在单击按钮时发出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);
    }
});

但是,请求被发送到服务器两次。

-点击事件肯定只触发一次!

-如果我手动浏览到 strURL 中的 URL,服务器端函数只触发一次,因此它似乎不是服务器端的任何内容。

但是(相同,除了 url)应用程序中其他地方的 ajax 请求只触发一次,我看不出有任何区别!

我该如何追踪?

我可以通过在服务中将重定向到 doPost 从 doGet 来重现该行为,例如:

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 方法,但我现在想不起了。话虽如此,你的servlet不会运行两次,而是同时运行doGet和doPost。