跨域问题解决

参考:http://www.51testing.com/html/96/215196-829360.html

IE10+才支持withCredentials属性

IE9-不支持,跨域对象只能用XDomainRequest对象,而jQuery并不兼容XDomainRequest。。

所以你要跨域只能自己写兼容代码,判断是否IE9-,是的话自己用XDomainRequest来跨域。

如果你能控制数据源页面,改为jsonp的数据格式,这样就任何域都可以请求获取到数据。

解决:可通过nginx 配置

在nginx.conf中配置:

http {

  ......

  add_header Access-Control-Allow-Origin *;

  add_header Access-Control-Allow-Headers X-Requested-With;

  add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

  ......

}

这样就可以实现GET,POST,OPTIONS的跨域请求的支持

也可以 add_header Access-Control-Allow-Origin http://test.51testing.com; --指定允许的url;

实际生产环境可用此方法解决。

猜你喜欢

转载自luchangbin-java.iteye.com/blog/2310492