转自:http://blog.csdn.net/leon90dm/article/details/8120378

http://my.oschina.net/LinBandit/blog/33160

使用JQuery的ajax出现

XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin

解决办法:

  1.如果请求的是的url是PHP的,须要PHP中文件前头加入

echo header("Access-Control-Allow-Origin:*");

  2.如果请求的html的,这需要加入

<meta http-equiv="Access-Control-Allow-Origin" content="*">

原因如下:

后来查到错误原因是:

使用xmlhttprequest获取服务数据时,在IE下能通过而在 chrome不能通过的问题,这就是所谓的跨域问题,什么是跨域呢?比较不规范但是通俗的说说法吧,比如你使 用chrome打开一个本地的html页面,那么我认为现在你的机器就是一个站点,这个html就是运行在这个站点上,如果你要在这个html页面中通过 xmlhttprequest获取百度的页面源码信息,就有点跨域的意思,这和你直接在地址栏上输入www.baidu.com又不一样,因为那样的话, 你当前的站点就是百度了,如果百度也在他的主页上通过xmlhttprequest获取google的页面信息,那样应该也算是跨域了吧,但是这个跨域问 题在服务器上是不存在的,你在服务器上使用urlHttpConnection连接其他站点是允许的。

可以想象,你连接到你自己的服务器,打开一个页面,如果这个页面要获取google的数据,那么这个页面可以向服务器发出请求(这个页面和这个服务 器是同一个域,我通俗的理解,所以这个请求没问题),服务器根据请求向google获取数据(这个是允许的),然后服务器再将获取到的数据反馈回页面,这 样页面就获取到google的数据了。

具体代码怎么写就不在话下啦!

最后可以通过服务器来解决这个问题,但至于为什么IE8可以允许跨域访问我就不清楚了!

=====================分隔符===============================

加料:

转自:http://www.cnblogs.com/accessking/archive/2012/05/12.html

在学习XMLHttpRequest的使用过程中,使用chrome打开任意空网页,在控制台下输入如下代码

1 var oHttp=new XMLHttpRequest();2 undefined3 oHttp.open('GET','http://www.baidu.com/')4 undefined5 oHttp.send();6 undefined7 XMLHttpRequest cannot load http://www.baidu.com/. Origin null is not allowed by Access-Control-Allow-Origin.

报错部分的英文的大概意思就是不允许跨域,至于什么叫做不允许跨域呢?

请看上面解释。

我尝试了chrome、firfox、opera都出现了这种情况,但是使用IE8就不会出现这种错误,很多人不是很理解。

这里Windows help and support 做出了解释  IE本身也并不是允许跨域的因为这样很不安全,但是如果不跨域的话又带来很多不便,所以会让你手动的选择一下是否允许跨域。而chrome、firfox、opera则默认就是不允许。

What is active content and why does Internet Explorer restrict it?

Active content is interactive or animated content used on websites. It includes ActiveX controls and web browser add-ons, which are small programs that are used extensively on the Internet. Active content can make web browsing more enjoyable by providing toolbars, stock tickers, video, animated content, and more.

Why does Internet Explorer restrict active content?

Internet Explorer restricts this content because occasionally these programs can malfunction or give you content you don't want. In some cases, these programs can be used to collect information about you, damage information on your computer, install software without your consent, or allow someone else to control your computer remotely. Given these risks, you should allow active content only if you completely trust the publisher or the website it's coming from.

How can I allow active content?

If Internet Explorer restricts active content that you are sure you want to allow, click the gold Information bar that appears at the top of the webpage, and then click Allow blocked content. For more information, see Internet Explorer Information bar: frequently asked questions.

转载于:https://blog.51cto.com/frabbit2013/1254709

Origin null is not allowed by Access-Control-Allow-Origin 解决方法相关推荐

  1. Access to script at ‘xxx‘ from origin ‘null‘ has been blocked by CORS policy: Cross origin requests

    前言 本地调试js时,遇到本错误 Google Chrome 84.0.4147.135 (正式版本) (64 位) (cohort: Stable Installs Only) 修订版本 c42bd ...

  2. Chrome浏览器报错:Origin null is not allowed by Access-Control-Allow-Origin.

    问题:Chrome浏览器报错:Origin null is not allowed by Access-Control-Allow-Origin. 原因:.js文件中使用load()方法,而Chrom ...

  3. 【VSCode】from origin ‘null‘ has been blocked by CORS policy: Cross origin requests are only supported

    Access to script at 'file:///C:/Users/dawulei/Desktop/%E9%A1%B9%E7%9B%AE/%E5%9D%A6%E5%85%8B%E5%A4%A7 ...

  4. ASP+Access中文乱码的解决方法,ASP中文乱码,asp乱码问题

    确保编码声明正确(例:时尚淘女之家http://www.tao36524.com) 如果您使用的是国外空间,默认是西欧而不是GB2312,你可以通过强制为GD2312的方式! 在数据提取页面的第一行代 ...

  5. aspx mysql 安全问题_ASP+access的安全问题及解决方法

    时 间:2009-08-11 08:38:09 作 者:摘 要:ASP+Access的安全问题及解决方法 正 文: 随着Internet的发展,Web技术日新月异.继通用网关接口(CGI)之后,&qu ...

  6. 提示YOU DON'T HAVE PERMISSION TO ACCESS / ON THIS的解决方法

    Forbidden  You don't have permission to access / on this server.   解决办法 打开 httpd.conf 文件, 将 #  onlin ...

  7. mysql ERROR 1045 (28000): Access denied for user解决方法

    参考:http://blog.sina.com.cn/s/blog_759a5a7c01017dj0.html 以下环境是ubuntu. 1, 打算修改mysql的密码.按网上的方法修改mysql的r ...

  8. Forbidden You don't have permission to access / on this server.解决方法

    wamap本地搭建完毕后,输入http://localhost/出现下面的问题 问题报错:Forbidden You don't have permission to access / on this ...

  9. git报错:‘origin‘does not appear to be a git repository的解决方法

    文章目录 #事故现场 #解决方法 #事故现场 git push origin master时报错: fatal: 'origin' does not appear to be a git reposi ...

最新文章

  1. Spring中的JDBC操作
  2. Fragment-FragmentMannager中的方法
  3. iPhone内运行python,返回Killed: 9 ,iOS内安装python2.7等问题的解决方法
  4. 文件上传到ftp服务工具类
  5. strom-1.1.0模拟单词统计功能,Spout编写,Bolt编写,TopologyDriver编写,本地模式运行,集群模式运行,集群模式下看输出结果
  6. android 使用c 代码实现,JNI开发实现helloworld,调用自己的C代码实现(1)
  7. mysql导入sql文件过大或连接超时的解决办法
  8. 2018php项目实战视频教程,2018PHP实战技术VIP在线学习视频课程
  9. 奥巴马:乔布斯改变我们每个人看世界的方式
  10. 阿里工程师手把手教你设计 B 端垂类营销中心!
  11. Airbnb 面试题汇总
  12. 在写易买网时产生的错误 JSTL标签库中c:choose/c:choose不能放JSP页面!-- --注释...
  13. DSShop单用户TP5框架B2C开源商城源码v3.0.2
  14. 软件需求说明书模板1
  15. 制作dnf脚本Java_易语言制作DNF解封源码
  16. postgresql注入笔记
  17. ubantu 安装jekins
  18. 新书《完美统计图:Word/PPT/Excel数据可视化宝典》,包邮送
  19. CVPR:Refining Pseudo Labels with Clustering Consensus over Generations for Unsupervised Object Re-ID
  20. linux替换变量字符串,linux shell 替换字符串的几种方法,变量替换${},sed,awk

热门文章

  1. 大二暑假周进度报告(五)
  2. [svc]数字证书基础知识
  3. 上半年产品原型设计Axure rp稿(持续更新)
  4. Mac下ssh支持auto complete
  5. Asprise OCR SDK 15.3试用版破解
  6. 非阻塞模式(ioctlsocket)
  7. IOS开发设置应用程序App启动图片
  8. linux7有相当于wget的,centos7安装mwget下载资源,提升下载速度
  9. java url gbk编码转换_如何在一个utf-8编码的HTML中 在javascript中url跳转时把url中的汉字改为GBK编码...
  10. 如何改善mysql数据装载操作效率的方法_详述如何提高MySQL中数据装载效率