Access to XMLHttpRequest at 'http://100.38.131.120:8080/nweb-service/nwebService/trade.action?action=sendTrade' from origin 'http://localhost:8083' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
时间: 2023-07-24 14:55:05 浏览: 62
这个错误是因为浏览器的同源策略(Same Origin Policy)导致的。同源策略是指浏览器只允许在同一域名下的页面之间相互访问,而不能跨域名进行访问。而这个错误提示的意思是,你的前端页面是从`http://localhost:8083`这个域名下加载的,但是你的请求`http://100.38.131.120:8080/nweb-service/nwebService/trade.action?action=sendTrade`是发往`100.38.131.120`这个IP地址的服务器,两者域名不同,因此被阻止了。
要解决这个问题,可以在后端服务器上设置CORS(Cross-Origin Resource Sharing)策略,允许跨域访问。具体的做法是在服务器的响应头中添加以下内容:
```
Access-Control-Allow-Origin: http://localhost:8083
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type, X-Requested-With
```
其中,`Access-Control-Allow-Origin`表示允许的跨域来源,`Access-Control-Allow-Methods`表示允许的跨域请求方法,`Access-Control-Allow-Headers`表示允许的跨域请求头。
如果你没有权限修改后端服务器的配置,也可以使用一些工具来绕过浏览器的同源策略,例如JSONP、CORS代理等。但是这些方法都有一定的限制和安全性问题,请谨慎使用。