1、最近调用身份证读写器硬件因为项目部署电脑和身份证读写器链接的电脑不是同一台电脑,ajax请求出现了CORS跨域。现记录下谷歌浏览器解决方法。
ajax请求方法:
jQuery.ajax({
type: "get",
url: "http://localhost:9000/api/ReadMsg?ie=1&Fp=1",
dataType: "JSONP",
success: function (result) {
console.log(result)
},
error: function (e) {
console.log("身份证读卡器错误!");
}
});
2、因为调用的是硬件接口,没法通过后台方法解决跨域问题,只能通过前端接口进行处理。
谷歌浏览器最新版本chrome94版本后,会出现Access to XMLHttpRequest at ‘http://localhost:xxxx/api’ from origin ‘http://xxx.xxx.com:xxxx’ has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space local
.
3、解决方法
3.1 打开谷歌浏览器,在地址栏输入chrome://flags/进入下方页面
3.2 在搜索栏搜索Block insecure private network requests并设置为Disabled,重新打开浏览器就好了