Google Web Toolkit (GWT), getting legacy JavaScript code to make AJAX calls through GWT app (to get around same origin policy)?
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 communicat开发者_开发知识库e with the spring app on a different port. Any advice is greatly appreciated.
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.
精彩评论