在每次 AJAX 调用之前/之后运行 JS 方法

发布于 2024-09-06 04:52:48 字数 250 浏览 1 评论 0原文

我正在使用 AJAX.NET,包括更新面板、Web 服务调用、客户端控件等。

在 5 月页面中,我包含第 3 方 javascript 文件,该文件在有限的预配置时间(例如 30 分钟)内进行保持活动调用。这个脚本是我的会话管理员。

每次用户与浏览器交互时 - 我想运行此脚本中的一个方法来重置计数器新的 30 分钟。

在我所有的ajax调用之前/之后是否有一个地方可以放置此方法调用,而不是在任何地方执行数十次?

谢谢。

I'm using AJAX.NET including update panels, web service calls, client controls etc.

In may page I include 3rd party javascript file that makes keep-alive call for limited preconfigured amount of time (say 30 min). this script is my session keeper.

every time the user have an interaction with the browser - i want to run a method in this script to reset the counter for new 30 min.

Is there a place that is prior / later to all my ajax calls where i can put this method call instead doing that everywhere dozens of times?

Thanks.

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

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

发布评论

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

评论(2

少年亿悲伤 2024-09-13 04:52:48

我不确定是否有办法捕获每个 ajax 调用,但下面的处理程序将在每次异步回发(例如 updatepanel)后触发

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler)

更多信息:http://msdn.microsoft.com/en-us/library/bb383810.aspx

正如Chaotic_one提到的,jQuery确实有全局的概念每次 ajax 调用之前/之后触发的事件,但我认为这仅指使用 jQuery 进行的调用。

I'm not sure if there is a way to catch every ajax call, but the handler below will fire after every asynchronous postback(eg updatepanel)

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler)

More info here: http://msdn.microsoft.com/en-us/library/bb383810.aspx

As Chaotic_one mentioned, jQuery does have the concept of global events that fire before/after every ajax call, but I think that only refers to calls made using jQuery.

纵情客 2024-09-13 04:52:48

那么,您必须将 AJAXing 函数绑定到每个浏览器事件。 这里是关于 JS 事件的更多信息。如果你使用 jQuery,事件将会变得更加简单。

但我不明白的是为什么不使用 .NET Session 类?

Well, you have to bind your AJAXing function to every browser event. Here is more about JS events. If you use jQuery, events will become much simplier.

But what I didn't get is why just don't make use of .NET Session class?

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