AJax+Servlet 跨域问题 Access-Control-Allow-Origin
2017-06-28 09:41
417 查看
解决报错
XMLHttpRequest cannot load http://192.168.31.151/smartcity/add.PHP. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8156’ is therefore not allowed access.
在 Servlet 的头部加上
response.setHeader(“Access-Control-Allow-Origin”, “*”);
如果你不想所有请求到此 Servlet 的 request 都通过 , 可以改为
response.setHeader(“Access-Control-Allow-Origin”, “yoururl”);
XMLHttpRequest cannot load http://192.168.31.151/smartcity/add.PHP. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8156’ is therefore not allowed access.
在 Servlet 的头部加上
response.setHeader(“Access-Control-Allow-Origin”, “*”);
如果你不想所有请求到此 Servlet 的 request 都通过 , 可以改为
response.setHeader(“Access-Control-Allow-Origin”, “yoururl”);
相关文章推荐
- Ajax访问Servlet的跨域请求问题—Access-Control-Allow-Origin
- 解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.
- Ajax 跨域问题(JSONP && Access-Control-Allow-Origin)
- Ajax请求跨域问题,报错XMLHttpRequest cannot load ''. No 'Access-Control-Allow-Origin' header is present on t
- ajax请求node.js接口时出现跨域问题Access-Control-Allow-Origin
- 解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin
- Ajax跨域问题的解决方法之一 —— "Access-Control-Allow-Origin"
- 解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.
- Ajax 跨域请求 Access-Control-Allow-Origin 问题
- 解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.
- 解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.
- ajax Access-Control-Allow-Origin跨域问题
- 调用其他服务器的api时,暂时处理跨域问题的方法——No 'Access-Control-Allow-Origin' header is present on the requested resour
- chrome发起跨域ajax请求遇到 Origin null is not allowed by Access-Control-Allow-Origin 一解
- Access-Control-Allow-Origin:ajax 跨域访问
- Access-Control-Allow-Origin:ajax 跨域访问
- HTML5 Access-Control-Allow-Origin解决跨域问题
- Chrome报错:跨域问题处理( Access-Control-Allow-Origin)_ 用于本地测试的快捷解决方法
- ajax 跨域 Access-Control-Allow-Origin
- 解决NodeJS+Express模块的跨域访问控制问题:Access-Control-Allow-Origin