读取本地xml或json等本地文件报错Failed to load file:///D:/xml/test.xml: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
问题如上图;
原因及解析:
在浏览器打开本地的html文件, 上面proxy中的url获取的就是一个本地文件, 协议是file://,如果是在服务器启动的话,则使用的是http或者https协议。
出于安全性考虑, Chrome默认禁止了这种用法,file协议和http/https协议不同,会被Chrome认为是跨域访问,所以会报被CORS(Cross-Origin Resource Sharing,跨域资源共享)的安全策略阻止。
原文链接:https://blog.csdn.net/oscar999/article/details/124114343
可以解决的方式是:
将Html文件挂在IIS上以网站方式去访问
读取本地xml文件参数,获取要得到的图片名,判断图片是否存在
var xmlObj = false;
function DownloadPng() {
//判断是否是IE浏览器
if (window.ActiveXObject) {
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlObj = new XMLHttpRequest();
}
xmlObj.open('GET', 'PngInfo.xml', true);
//使用异步方式所以要在XMLHttpRequest对象的状态改变时做相应的处理
xmlObj.onreadystatechange = function () {
//判断XMLHttpRequest的状态,如果是4 ,继续处理
if (xmlObj.readyState == 4) {
//需要判断返回状态时否是200
if (xmlObj.status == 200) {
DoXml();
}
}
}
//发送请求,因为是GET,所以send的内容是null
xmlObj.send(null);
function DoXml() {
var xmlDoc = xmlObj.responseXML;
var imageName = xmlDoc.getElementsByTagName("location")[0].childNodes[0].nodeValue;
console.log(imageName);
var location = "file/" + imageName + ".png";
xmlObj.open("Get", location , true);
xmlObj.send();
if (xmlObj.status == 404) {
console("图片不存在");
} else {
console("图片存在");
} }
访问的html 后缀待参数,读取参数作为文件名
例如 http://10.0.xx.xxx:8090/download.html?imagename=sssxx01
var ImageName = "";
urlinfo = window.location.href; //获取当前页面的 len = urlinfo.length;//获取url的长度 offset = urlinfo.indexOf("?");//设置参数字符串开始的位置
if (offset == -1) {
ImageName = "不存在";
}
else {
newsidinfo = urlinfo.substr(offset, len)//取出参数字符串 这里会获得类似“id=1”这样的字符串
newsids = newsidinfo.split("=");//对获得的参数字符串按照“=”进行分割 newsid=newsids[1];
ImageName = newsids[1];
}
读取本地xml或json等本地文件报错Failed to load file:///D:/xml/test.xml: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.的更多相关文章
- jquery读取本地文件,Windows上报错。XMLHttpRequest cannot load xxx. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.k.cors.a.c
问题: 测试报告,使用本地的json.txt文件,结果文件读取失败,报错如下: XMLHttpRequest cannot load xxx. Cross origin requests are on ...
- 【chrome错误】Cross origin requests are only supported for protocol schemes: http, data,chrome-extension, https, chrome-extension-reso
使用ajax请求本地文件,chrome会报跨域错误. XMLHttpRequest cannot loadfile:///C:/Users/Li/Desktop/images/alist.json.C ...
- nodejs报错 XMLHttpRequest cannot load localhost:3000/test_date/. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
z在请求本地的时候 如果ajax的URL 前面没有http的话 就会报错 jq.js:2 XMLHttpRequest cannot load localhost:3000/test_date/. ...
- 【Google Chrome】 Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource问题解决
问题??打开Google Chrome浏览器报错如下: 结论 浏览器出于安全性考虑,默认对跨域访问禁止 解决方法 给浏览器添加启动参数 --allow-file-access-from-files ...
- XMLHttpRequest cannot load file:///E:/userdialog.html?_=1465888805734. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-reso
做前端写静态页面时,采用的是jq easyui框架 在ie与webkit总是加载的时候总是在loading... 而firefox却是正常加载的,总以为是代码写错了, 经过再三的检查以及百度查找,确认 ...
- 如何解决XMLHttpRequest cannot load file:~~~~~~~~~~~. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-res
原因:Chrome不支持本地Ajax请求. 解决: 右击Chrome浏览器快捷方式,选择“属性”,在“目标”中加上"--allow-file-access-from-files", ...
- Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
转自:https://www.zhihu.com/question/20948649?sort=created 我最近也遇到这个问题了,用传统的快捷方式加参数并没有用,不知道是不是和chrome版本有 ...
- 本地数据访问时出现跨域问题Cross origin requests are only supported for protocol schemes: ……
从桌面找到Chrome图标,右键属性,快捷方式,起始位置(安装路径) 注:在cmd中访问Program Files文件的方法 %ProgramFiles%=C:\Program Files %Prog ...
- Ajax本地跨域问题 Cross origin requests are only supported for HTTP
问题:打开本地html文件时,报错如下 Cross origin requests are only supported for protocol schemes: http, data,chrome ...
- 云笔记项目- 上传文件报错"java.lang.IllegalStateException: File has been moved - cannot be read again"
在做文件上传时,当写入上传的文件到文件时,会报错“java.lang.IllegalStateException: File has been moved - cannot be read again ...
随机推荐
- 225-基于XCVU440T的多核处理器多输入芯片验证板卡
225-基于XCVU440T的多核处理器多输入芯片验证板卡 基于XCVU440T的多核处理器多输入芯片验证板卡 一.板卡概述 本板卡系我司自主研发的基于6U CPCI处理板,适用于多核处理器多输入 ...
- [jQuery]判断页面是否滚动到底部
方法1:判断可见高度+滚动高度是否等于内容高度 但经过测试UC.QQ.华为浏览器,这个方法不生效.(打印查因:可能由于屏幕缩放,可见高度和滚动高度会偏小. $(this).scroll(functio ...
- Excel之VLOOKUP()函数的基本用法
语法: VLOOKUP(lookup_value,table_array,col_index_num,[range_lookup]) 规则: 注意: 查找的值:内容需要完全一样 查找范围:查找范围的 ...
- CSS控制背景图片100%自适应填充布局
原文地址:http://blog.csdn.net/wd4java/article/details/50537562 .personal_head { width: 100%; height: 35% ...
- 菜狗记录pycharm使用问题
1.
- Angular单页应用程式 (SPA)+Azure AD重新导向登入
一.app.module.ts中设定应用程式 1.将MSAL Angular相关设置封装为auth.module.ts import { NgModule } from '@angular/core' ...
- [1] Multi-View Transformer for 3D Visual Grounding 论文精读
参考: https://zhuanlan.zhihu.com/p/467913475 3D Visual Grounding小白调研笔记 https://zhuanlan.zhihu.com/p/34 ...
- 【根文件系统 】开发板通过nfs挂载ubuntu上的根文件系统
在此基础上制作可用的根文件系统:https://www.cnblogs.com/hengqiu/p/15908597.html 1.ubuntu搭建nfs服务器 sudo apt-get instal ...
- Kubernetes-yaml详解
目录: Yaml语法格式 查看api资源版本标签 deployment模板 service模板 查询帮助和格式指令 Pod模板 写 yaml太累怎么办 yaml文件的学习 方法 deployment. ...
- python 删除大于超过一定时间文件
import os from datetime import datetime, timedelta path = "." if __name__ == '__main__': f ...