来自动作脚本的同步服务器调用
如何通过动作脚本进行同步服务器调用(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,你不能像在 Javascript 中那样对服务器进行同步调用。
我的理解是,您希望 swf 在关闭浏览器窗口之前调用服务器 - 可能是为了记录会话中使用的时间
您可以执行以下操作:
在闪存中:添加回调函数(A )在 Flash 中使用 ActionscriptExternalInterface 执行以下操作:
A) 使用 URLLoader 调用服务器并将方法指定为 POST。
B) 当 urlloader Event.COMPLETE 处理程序触发时,通过ExternalInterface 调用 window.close
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:
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
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!