Ajax onSuccess 回调,但无法控制 ajax 调用

发布于 2024-07-13 19:03:47 字数 188 浏览 9 评论 0原文

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

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

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

谢谢。

I have a simple JS function that needs to get called when AJAX call succeeds, however i don't have any control over the AJAX calls since the framework (DNN5) handles all that.

How do i call my function on AJAX success?

I use DNN5 and jQuery, if you're not familiar with DNN, just assume that all the controls on the page are wrapped in the asp:UpdatePanel.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最近可好 2024-07-20 19:03:47

我不熟悉 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 调用

I'm not familiar with DNN5, but am with UpdatePanels. Can you hook into the Client events of an async postback in ASP.NET AJAX i.e. add an eventhandler to the PageRequestManager endRequest event.

As an example,

  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
      }  
  }

EDIT:

Thinking about it, I'm not sure whether this will work for you. It'll depend on how DNN5 performs the AJAX calls within ASP.NET

新人笑 2024-07-20 19:03:47

@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>

@Russ: just saw your answer, i'll test it, and if it works i'll accept it.

shortly after posting this question, i recalled that i had the similar problem in my previous project, so i went back and got the code from there:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文