最近做一个项目,前台jsp页面通过ajax调用action返回结果,测试发现错误:
XMLHttpRequest cannot load http://xxxxxxxxxx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
jsp页面调用代码如下:
$.ajax({
url:'',
type:'post',
dataType:'json',
success:function(data,status){
alert(1);
}
});
这是个跨越访问报错,百度发现前辈提供的方法都不能解决我的错误。不过在查看老外网站设置一下response的headers就ok
response.setHeader("Access-Control-Allow-Origin", "*");