Chrome - 浏览器跨域访问设置(附:新老版本两种设置方法)

在进行前后分离的 webapp 开发,或者 H5 移动 App 开发时,我们会使用 PC 端浏览器进行开发调试。但默认情况下 Ajax 请求无法跨域访问,请求时会报如下错误: 

XMLHttpRequest cannot load http://127.0.0.1:8080/ptmo/services/ptmo/v1/execOneSql. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8020' is therefore not allowed access.

原文:Chrome - 浏览器跨域访问设置(附:新老版本两种设置方法)

下面介绍如何通过设置 Chrome 使其支持跨域。 由于新版本的设置方法和以前不一样,下面分别进行介绍。

一、老版浏览器的跨域设置(版本号49之前)

(1)右键点击 Chrome 快捷方式图标,选择“属性”。

(2)在属性页面中的目标输入框尾部加上: --disable-web-security

原文:Chrome - 浏览器跨域访问设置(附:新老版本两种设置方法)

(3)点击“应用”并关闭属性页面。重新打开 chrome 浏览器。如果浏览器出现提示“你使用的是不受支持的命令标记 --disable-web-security”,那么说明配置成功。

原文:Chrome - 浏览器跨域访问设置(附:新老版本两种设置方法)

二、新版浏览器的跨域设置(版本号49起)

(1)在电脑上新建一个目录,例如:C:\MyChromeDevUserData

(2)在属性页面中的目标输入框里加上: --disable-web-security --user-data-dir=C:\MyChromeDevUserData

原文:Chrome - 浏览器跨域访问设置(附:新老版本两种设置方法)

(3)点击应用和确定后关闭属性页面,并打开 chrome 浏览器。发现有“--disable-web-security”相关的提示,说明 chrome 已经可以正常跨域工作了。


原文出自:www.hangge.com  转载请保留原文链接:http://www.hangge.com/blog/cache/detail_1703.html

猜你喜欢

转载自www.cnblogs.com/turnip/p/12195137.html