【问题标题】:sencha touch ajax request called twicesencha touch ajax 请求调用了两次
【发布时间】:2012-06-08 03:34:53
【问题描述】:

我的 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 请求只触发一次,我看不出有任何区别!

我该如何追踪?

【问题讨论】:

  • 您是如何得知 Ajax 请求被触发两次的?控制台上有任何操作吗?
  • 服务在服务器上被调用两次,每次应用触发事件一次。
  • 我也有同样的问题。你找到解决办法了吗?

标签: javascript ajax sencha-touch-2


【解决方案1】:

我可以通过在我的服务中从 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。

【讨论】:

  • 我很久以前就离开了 Sencha,但感谢您的洞察力。希望其他人会觉得它有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-20
  • 1970-01-01
  • 2012-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多