jQuery发送ajax请求实现跨域访问

时间:2024-06-23 12:32:56

Java代码的话,在返回响应之前调用如下代码中的allowCrossDomainAccess()方法:

/**
* 允许跨域访问
*/
public void allowCrossDomainAccess(HttpServletResponse response){
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "*");
response.setHeader("Access-Control-Allow-Headers:x-requested-with", "Authorization,Origin,X-Requested-With,Content-Type,Accept,content-Type,origin,x-requested-with,content-type,accept,authorization,token,id,X-Custom-Header,X-Cookie,Connection,User-Agent,Cookie");

参考:

https://blog.****.net/ldx891113/article/details/50887776

https://blog.****.net/fdipzone/article/details/46390573

https://blog.****.net/moxiaoya1314/article/details/80430300

全文完

:)