简体   繁体   中英

CrossDomain ajax request using CORS

I am trying to POST to my cross domain * Rest service * via javascript, and realized that's not possible unless I use this specfication;

http://www.w3.org/wiki/CORS_Enabled

But there is very limited documentation how I can implement this, I have a few questions;

1- I use Glassfish Jee6 app server so can I simply add a jetty filter to my web.xml and job is done?

2- And for client side(mobile website), is there any javascript library which helps to implement this specification? Can I still use the existing ajax functions in JQuery or I need something more specific?

Jetty filter:

<web-app>
 <filter>
   <filter-name>cross-origin</filter-name>
   <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
   <init-param>
       <param-name>allowedOrigins</param-name>
       <param-value>*</param-value>
   </init-param>
   <init-param>
       <param-name>allowedMethods</param-name>
       <param-value>*</param-value>
   </init-param>
   <init-param>
       <param-name>allowedHeaders</param-name>
       <param-value>*</param-value>
   </init-param>
 </filter>
 <filter-mapping>
     <filter-name>cross-origin</filter-name>
     <filter-pattern>*</filter-pattern>
 </filter-mapping>
</web-app>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM