js bug: Origin 'null' is therefore not allowed access.
来源:互联网 发布:大数据时代影响 编辑:程序博客网 时间:2024/05/25 12:22
先说一下问题的由来,在本地html页面ajax请求本地或者局域网server的资源时遇到的bug,先来段出问题的代码:
<script type="text/javascript"> $.ajax({ type:"get", url:"http://192.168.199.59:9000/api/v1/questions/5825acefffa2f815acdb03cf", success:function(res){ console.log(888); }, error:function(){ console.log(66666) } });</script>
翻译一下大家的解释好了: Origin null is not allowed by Access-Control-Allow-Origin
意味着你在尝试ajax请求本地文件,因为安全的原因,这是被禁止的。
服务端的做法是在response内允许这么做:
response.setHeader("Access-Control-Allow-Origin", "*")
如果Chrome浏览器的话可以尝试加入新的插件:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related
来个参考文献
Chrome Origin null is not allowed by Access-Control-Allow-Origin
0 0
- js bug: Origin 'null' is therefore not allowed access.
- 如何解决XMLHttpRequest cannot load file~~~~~~~Origin 'null' is therefore not allowed access
- 如何解决XMLHttpRequest cannot load file~~~~~~~Origin 'null' is therefore not allowed access
- 如何解决XMLHttpRequest cannot load file~~~~~~~Origin 'null' is therefore not allowed access
- 问题:XMLHttpRequest cannot load file~~Origin 'null' is therefore not allowed access
- 如何解决XMLHttpRequest cannot load file~~~~~~~Origin 'null' is therefore not allowed access
- 如何解决XMLHttpRequest cannot load file~~~~~~~Origin 'null' is therefore not allowed access
- 如何解决XMLHttpRequest cannot load file~~~~~~~Origin 'null' is therefore not allowed access
- Origin null is not allowed by Access-Control-Allow-Origin.
- Origin null is not allowed by Access-Control-Allow-Origin
- Origin null is not allowed by Access-Conntrol-Allow-Origin
- XMLHttpRequest Origin null is not allowed by Access-Control-Allow-Origin
- JQuery 的 ajax 出现Origin null is not allowed by Access-Control-Allow-Origin 解决方法
- XMLHttpRequest在请求失败(Origin null is not allowed by Access-Control-Allow-Origin.)
- Origin null is not allowed by Access-Control-Allow-Origin解决方案
- XMLHttpRequest在请求失败(Origin null is not allowed by Access-Control-Allow-Origin.)
- XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin
- jquey XMLHttpRequest cannot load url.Origin null is not allowed by Access-Control-Allow-Origin
- 写的都是看到的——面向对象编程(一)
- NOIP应试技巧
- 【HDU 5914 Sequence I】+ 2016中国大学生程序设计竞赛(长春)-重现赛
- size()\pyrDown\pyrUp
- 【连接调试】之迷茫的2440第一课
- js bug: Origin 'null' is therefore not allowed access.
- 【快速幂】
- mac下修改mysql初始密码问题
- 安卓开发之弹出输入法后顶起布局最简单有效方法
- LeetCode 445. Add Two Numbers II
- Solr安装及使用示例
- 【图论最短路】【CQBZOJ 2432】Maze
- Unity3D占用内存太大的解决方法
- 利用ViewStub实现错误页面的展示