0

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

但是请求被发送到服务器 TWICE。

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

- 如果我手动浏览到 strURL 中的 URL,服务器端函数只会触发一次,所以它似乎不是服务器端的任何东西。

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

我该如何去追踪这个?

4

1 回答 1

0

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

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。

于 2014-06-13T08:33:53.613 回答