利用 pyhon 解决 Cross Origin Requests
在学习 ajax 时遇到了一个问题
XMLHttpRequest cannot load file:xxxxxxxx . Cross origin requests are only supported for HTTP.
谷歌了下, 在stackoverflow 上发现了原因所在:XMLHttpRequest 必须通过服务器打开,不能直接本地在文件目录下打开, 如下图:

同时也介绍了几种解决方法,既然要通过服务器, 肯定要先开, apache什么的 有的自然最好, 但还有中更方便的方法, 通过 python 的 SimpleHTTPServer.
具体方法是: 通过控制台进入所需要打开的文件目录下, 然后执行命令 python -m SimpleHTTPServer 8000 , 在打开 http://localhost/,就会看到该目录下的子目录了.

如果http://localhost// 显示无法打开网页, 可能是端口被占用了, 换其他的试试。
利用 pyhon 解决 Cross Origin Requests的更多相关文章
- 用临时用户数据目录启动Chrome,关闭安全检查等(解决Cross origin requests are only supported for HTTP?)
Cross origin requests are only supported for HTTP? 参考:https://www.zhihu.com/question/20948649 批处理: s ...
- Ajax本地跨域问题 Cross origin requests are only supported for HTTP
问题:打开本地html文件时,报错如下 Cross origin requests are only supported for protocol schemes: http, data,chrome ...
- 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 ...
- Cross origin requests are only supported for protocol schemes: http, data, chrome,chrome-extension的问题
Cross origin requests are only supported for protocol schemes: http, data, chrome,chrome-extension的问 ...
- 【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/. ...
- 跨域问题:Cross origin requests are only supported for protocol schemes: http...
跨域:Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extensi ...
- 如何解决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", ...
- 【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 ...
随机推荐
- asp.net core 设置默认文档index.html
参考:https://jingyan.baidu.com/article/6079ad0e3e212168fe86db75.html 在Startup.cs的Configure添加 app.UseFi ...
- Jetcache
转存 Jetcache https://github.com/alibaba/jetcache/wiki/GettingStarted_CN
- Asp.net Core全局异常监控和记录日志
前言 系统异常监控可以说是重中之重,系统不可能一直运行良好,开发和运维也不可能24小时盯着系统,系统抛异常后我们应当在第一时间收到异常信息.在Asp.net Core里我使用拦截器 ...
- Spring MVC(3)Spring MVC 高级应用
一.Spring MVC 的数据转换和格式化 前面的应用,都只是用HandlerAdapter去执行处理器. 处理器和控制器不是一个概念,处理器是在控制器功能的基础上加上了一层包装,有了这层包装,在H ...
- Java基础(十)接口(interface)
1.接口的概念 在Java中,接口不是类,而是对类的一组需求描述,这些类要遵从接口描述. 例如:Array类中的sort方法可以对对象数组进行排序,但要求满足下列前提:对象所属的类必须实现了Compa ...
- django-模板之extends(三)
/book/base.html <!DOCTYPE html> <html lang="en"> <head> <meta charset ...
- MongoDB系列---用户及权限管理02
MongoDB-——Privilege 学习大纲: 1.用户权限管理 2.用户操作 知识回顾: 本系列上一篇博文我们讲述了如何搭建环境以及配置我们的MongoDB,通过搭建环境后我们又学习了如何通过 ...
- 泛微ecology OA系统某接口存在数据库配置信息泄露漏洞
2漏洞详情 攻击者可通过该漏洞页面直接获取到数据库配置信息,攻击者可通过访问存在漏洞的页面并解密从而获取数据库配置信息,如攻击者可直接访问数据库,则可直接获取用户数据,由于泛微e-cology默认数据 ...
- C函数库stdio.h概况
库变量 size_t 这是无符号整数类型,它是 sizeof 关键字的结果. FILE 这是一个适合存储文件流信息的对象类型. fpos_t 这是一个适合存储文件中任何位置的对象类 ...
- makefile中":="和“=”的区别
在makefile中,经常能看到这种赋值方式: MyNumber := 这种方式洋名叫做expansion assignment, 翻译过来叫扩展赋值, 我一般就叫冒号等号.这位同学就问了,那么它和普 ...