Google Web Toolkit (GWT),获取旧版 JavaScript 代码以通过 GWT 应用程序进行 AJAX 调用(以绕过同源策略)?

发布于 2024-11-05 11:00:16 字数 660 浏览 4 评论 0原文

我正在开发一个应用程序,其中有大量使用 jQuery 的现有 JavaScript 并对 Spring 服务器端应用程序进行 AJAX 调用。该项目的范围超出了我最初的预期,因为该项目的业务经理最初并没有明确表示我们将在用户界面中添加许多相当复杂的功能。基本上,我觉得使用 JavaScript 现在是一个障碍,因为使用 GWT 会让事情变得更加顺利,但是,我不想重写应用程序的整个 JavaScript 部分,我只想开始在这些区域使用 GWT我需要它并让其余的继续工作。

问题是,我现在已将应用程序分为 2 个:Spring 和 GWT 应用程序,以便 Spring 将在与 GWT 应用程序不同的端口上运行。这是因为应用程序有很多复杂的服务器端代码,并处理搜索向量、在内存中加载每次重新启动时需要一段时间的大型对象等,以便将其与 UI 完全分开是最有意义的。我想我可以将 JavaScript 包含到我的 GWT .html 页面中,并且没有理由它不起作用(希望我的假设是正确的),因为它不会直接与任何 GWT 内容交互,但是因为由于具有相同的起源策略,我将无法对在不同端口上运行的 spring 应用程序进行 AJAX 调用。我希望有人可以提供有关解决方法的信息,以便我可以做一些事情,例如使用 GWT 为我进行 JavaScript AJAX 调用(它只是传递/接收数据)或类似的事情?我已经让 GWT 应用程序能够与不同端口上的 spring 应用程序进行通信。非常感谢任何建议。

I work on an application where there is a lot of existing JavaScript that uses jQuery and makes AJAX calls to a Spring server-side app. The scope of the project has gone beyond what I originally expected as the business manager of the project didn't make it clear initially that we would be adding a lot of fairly intricate functionality within the user interface. Basically I feel that using JavaScript is now a hindrance as using GWT would make things a lot smoother going forward, however,I don't want to rewrite the entire JavaScript part of the app, I would like to just start using GWT for the areas that I need it and keep the rest working.

The issue is that I have now separated the applications into 2, the Spring and the GWT app so that the Spring would be running on a different port than the GWT app. This is because the application has a lot of complex server-side code and deals with searching vectors, loading large objects in memory that takes a while each time its restarted, etc to where it makes the most sense to keep it separate from the UI entirely. I figure I can just include the JavaScript into my GWT .html page and there's no reason that it wouldn't work (hopefully I am right in assuming this) as it wouldn't be directly interacting with any of the GWT stuff, but because of the same origin policy, I wouldn't be able to make AJAX calls to the spring app running on a different port. I am hoping someone can help with info on a workaround so that I could possibly do something like using GWT to make my JavaScript AJAX calls for me (where it just passes through / receives the data) or something like this? I've already got the GWT app able to communicate with the spring app on a different port. Any advice is greatly appreciated.

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

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

发布评论

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

评论(1

寻梦旅人 2024-11-12 11:00:16

关于。纯 JavaScript 和 GWT 之间的交互:阅读 http://code.google.com/webtoolkit /doc/latest/DevGuideCodingBasicsJSNI.html - 这是一个很棒的文档,涵盖了两者之间交互的两个方向。您是对的,只需像往常一样包含脚本即可在 GWT 代码旁边运行纯 JS 非常简单。

关于。使用 GWT 绕过同源策略:GWT 不会获得普通 JavaScript 所没有的任何特殊权力或特权。

Re. interacting between plain JavaScript and GWT: Read http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html - it's a great document that covers both directions of interaction between the two. You are right that it is pretty straightforward to run plain JS next to GWT code just by including the script as always.

Re. using GWT to bypass the same-origin policy: GWT does not get any special powers or privileges that normal JavaScript does not have.

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