可以通过配置Nginx的反向代理服务器来解决CORS跨域问题。具体步骤如下:

1.在nginx.conf中增加以下代码:

location /ueditor/ { proxy_pass http://127.0.0.1:7070/; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }

2.重启Nginx服务器。

3.在前端代码中将请求地址修改为Nginx反向代理服务器的地址,例如:http://localhost/ueditor/jsp/controller?action=uploadimage。

这样就可以解决CORS跨域问题了

Access to XMLHttpRequest at http1270017070ueditorjspcontrolleraction=uploadimage from origin httplocalhost8090 has been blocked by CORS policy No Access-Control-Allow-Origin header is present on the r

原文地址: https://www.cveoy.top/t/topic/eNfj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录