来自动作脚本的同步服务器调用

发布于 2025-01-03 14:14:22 字数 66 浏览 2 评论 0原文

如何通过动作脚本进行同步服务器调用(POST)?我正在尝试对浏览器卸载事件执行调用 - 但我认为它需要同步才能被调用。

how do you make a synchronous server call (POST) via actionscript? I'm trying to execute a call on the browsers unload event - but I think it needs to be synchronous in order to get called.

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

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

发布评论

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

评论(1

一张白纸 2025-01-10 14:14:22

据我所知,你不能像在 Javascript 中那样对服务器进行同步调用。

我的理解是,您希望 swf 在关闭浏览器窗口之前调用服务器 - 可能是为了记录会话中使用的时间

您可以执行以下操作:

  1. 在闪存中:添加回调函数(A )在 Flash 中使用 ActionscriptExternalInterface 执行以下操作:

    A) 使用 URLLoader 调用服务器并将方法指定为 POST。

    B) 当 urlloader Event.COMPLETE 处理程序触发时,通过ExternalInterface 调用 window.close

  2. IN JSCRIPT:捕获浏览器的 onbeforeunload 事件并阻止它,并调用您在 flash 上的步骤 1 中定义的回调函数来执行服务器调用然后在完成工作后关闭窗口。

希望这有帮助!

As far as I know you can't make synchronous calls to server as in Javascript.

What I understand is that you want your swf to do a call to the server before closing the browser window - probably to log time used in a session

What you can do is the following:

  1. IN FLASH: Add a callback function (A) in Flash using Actionscript ExternalInterface that does the following:

    A) Does the call to server using URLLoader and specifying the method as POST.

    B) calls window.close via ExternalInterface when the urlloader Event.COMPLETE handler fires

  2. IN JSCRIPT: catch the onbeforeunload event of the browser and prevent it and call the call back function you defined in step 1 on flash to do the server call and then closes the window when it finishes the job.

Hope this helps!

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