【问题标题】:Ajax onSuccess callback while not having any control over ajax callsAjax onSuccess 回调,而对 ajax 调用没有任何控制
【发布时间】:2009-02-13 10:38:21
【问题描述】:

我有一个简单的 JS 函数,当 AJAX 调用成功时需要调用它,但是我无法控制 AJAX 调用,因为框架 (DNN5) 处理所有这些。

如何在 AJAX 成功时调用我的函数?

我使用的是 DNN5 和 jQuery,如果你对 DNN 不熟悉,就假设页面上的所有控件都包裹在 asp:UpdatePanel 中。

谢谢。

【问题讨论】:

    标签: javascript ajax asp.net-ajax jquery dotnetnuke-5


    【解决方案1】:

    我不熟悉 DNN5,但我熟悉 UpdatePanels。您能否在 ASP.NET AJAX 中挂钩异步回发的客户端事件,即向 PageRequestManager endRequest 事件添加事件处理程序。

    举个例子,

      var prm = Sys.WebForms.PageRequestManager.getInstance();
    
      prm.add_endRequest(EndRequest);
    
      // runs when async postback completes.
      function EndRequest(sender, args)
      {
      if (sender._postBackSettings.sourceElement.id) // the id of the element that raised the postback that is completing
          {
            //Do what you need to do here
          }  
      }
    

    编辑:

    考虑一下,我不确定这是否适合您。这将取决于 DNN5 如何在 ASP.NET 中执行 AJAX 调用

    【讨论】:

      【解决方案2】:

      @Russ:刚刚看到你的答案,我会测试它,如果它有效,我会接受它。

      在发布这个问题后不久,我想起我在之前的项目中遇到过类似的问题,所以我回去从那里获取代码:

      <script type="text/javascript">
      
      Sys.Net.WebRequestManager.add_completedRequest(onComplete);
      
      
      function onComplete(sender, args) { //call JS here
      }
      
      function pageUnload() {
          Sys.Net.WebRequestManager.remove_completedRequest(onComplete);
      }
      
      </script>
      

      【讨论】:

        猜你喜欢
        • 2020-01-27
        • 2012-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多