简体   繁体   English

使用CORS的CrossDomain Ajax请求

[英]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; 我试图通过javascript发布到我的跨域 * Rest服务 *,并且意识到除非我使用此规范,否则这是不可能的;

http://www.w3.org/wiki/CORS_Enabled 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? 1-我使用Glassfish Jee6应用服务器,所以我可以简单地在我的web.xml中添加一个码头过滤器并完成工作吗?

2- And for client side(mobile website), is there any javascript library which helps to implement this specification? 2-并且对于客户端(移动网站),是否有任何JavaScript库可帮助实现此规范? Can I still use the existing ajax functions in JQuery or I need something more specific? 我仍然可以在JQuery中使用现有的Ajax函数,还是需要更具体的东西?

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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