将 AJAX 与 Java Applet 结合使用时出现问题
我目前有一个 Java Applet,其中包含方法 callfromjs()。 Javascript 从小程序中调用此方法,这样我就不必处理笨重的小程序 GUI,然后我可以从 javascript 轻松地在 DOM 上创建响应。
问题是浏览器在首次加载小程序时挂起。为了解决这个问题,我想我可以使用 AJAX。 AJAX 调用包含 callfromjs() 的 PHP 文件。问题是请求返回,因为它是 PHP,并且它不等待 callfromjs() 检索内容。
关于我的问题:
- 有更好的方法来处理这个问题吗?
- 如果这个方法看起来没问题,我怎样才能强制请求不返回,直到 javascript 完成从小程序调用该方法?
I currently have a Java Applet which contains a method callfromjs(). Javascript calls this method from the applet so that I don't have to deal with the clunky applet GUI, and then I can create the responses on the DOM easily from javascript.
The problem is that the browser hangs while first loading the applet. To get around this, I figured I could use AJAX. The AJAX calls a PHP file which contains callfromjs(). The problem is that the request returns because it's PHP, and it doesn't wait for callfromjs() to retrieve the content.
On to my questions:
- Is there a better way to handle this?
- If this method seems ok, how can I force the request not to return until the javascript is finished calling the method from the applet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么问题是在小程序初始化时对小程序的 LiveConnect 调用挂起吗?
显而易见的解决方案是 JavaScript 最初忽略小程序。当小程序初始化时,它可以调用 JavaScript 来启用。
So the problem is a LiveConnect call into the applet hangs whilst the applet is initialised?
The obvious solution would be for the JavaScript to initially ignore the applet. When the applet is initialised it can then call into the JavaScript to enable.
我不确定我是否明白这里发生了什么。您是否希望通过小程序生成内容而不让小程序本身执行 GUI 工作?您是否因为小程序需要很长时间才能加载而陷入困境?
那么为什么不放弃 applet,提取重要的内容并将其作为 servlet 提供呢?通过(例如)DWR 与其交互,它允许对 Java 后端进行 AJAX 调用(通过公开Java 对象自动作为 Javascript 对象)。这意味着您的客户端 GUI 将快速/响应灵敏,并且您无需依赖小程序。
I'm not sure I understand what's going on here. Are you looking to generate content via an applet without having the applet perform the GUI work itself ? And are you stuck since the applet takes a long time to load ?
So why not dispense with the applet, extract the important stuff and make it available as a servlet ? Interact with it via (say) DWR, which allows AJAX calls to a Java backend (via exposing Java objects automatically as Javascript object). That means your client GUI will be fast/responsive and you have no applet reliance.