AJAX calls from Apache-hosted file to Tomcat servlet on same server failing
Why are my AJAX requests failing? I have a website
www.foo.com
, and I'm running Tomcat on the same server, www.foo.com:8080/services
. However, when a file on foo.com
makes an ajax call as such:
$.get("http://fo开发者_StackOverflow社区o.com:8080/services/action.do", null, myCallback );
I get an error response, rather than the xml document I get if I manually browser to the url given above. What could be going wrong here?
As Tomcat is running on a differemt port (8080 as opposed to 80) it's regarded as a different origin, so you're running into the same-origin policy:
Mozilla considers two pages to have the same origin if the protocol, port (if one is specified), and host are the same for both pages.
(My emphasis).
Although this comes from the Mozilla docs, the policy is implemented the same way in all browsers - well, all browsers that are safe to use ;-)
精彩评论