XMLHttpRequest cannot load ...谷歌浏览器跨域问题

HTML页面通过Ajax调用公网web服务时,浏览器请求发送成功,但是响应的 xhr.status==0,控制台报错如下

XMLHttpRequest cannot load http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx. Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access.

服务端为公网,是允许跨域访问的,所以原因出在客户端,即浏览器方面——谷歌浏览器默认不支持跨域访问

解决方法:

关闭浏览器窗口-》右击谷歌浏览器图标-》属性。弹出属性对话框。在目标栏最后添加 –args –disable-web-security –user-data-dir ,使浏览器允许跨域访问

《XMLHttpRequest cannot load ...谷歌浏览器跨域问题》

打开浏览器,显示如下信息说明浏览器已更改为允许跨域访问

《XMLHttpRequest cannot load ...谷歌浏览器跨域问题》

当然,不是经常进行基于浏览器的跨域访问的话建议还是不要开启跨域。

    原文作者:雪山上的蒲公英
    原文地址: https://www.cnblogs.com/zjfjava/p/9012765.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞