日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Origin null is not allowed by Access-Control-Allow-Origin 解决方法

發(fā)布時間:2023/12/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Origin null is not allowed by Access-Control-Allow-Origin 解决方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

轉(zhuǎn)自:http://blog.csdn.net/leon90dm/article/details/8120378

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


使用JQuery的ajax出現(xiàn)

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獲取服務(wù)數(shù)據(jù)時,在IE下能通過而在 chrome不能通過的問題,這就是所謂的跨域問題,什么是跨域呢?比較不規(guī)范但是通俗的說說法吧,比如你使 用chrome打開一個本地的html頁面,那么我認(rèn)為現(xiàn)在你的機(jī)器就是一個站點(diǎn),這個html就是運(yùn)行在這個站點(diǎn)上,如果你要在這個html頁面中通過 xmlhttprequest獲取百度的頁面源碼信息,就有點(diǎn)跨域的意思,這和你直接在地址欄上輸入www.baidu.com又不一樣,因?yàn)槟菢拥脑?#xff0c; 你當(dāng)前的站點(diǎn)就是百度了,如果百度也在他的主頁上通過xmlhttprequest獲取google的頁面信息,那樣應(yīng)該也算是跨域了吧,但是這個跨域問 題在服務(wù)器上是不存在的,你在服務(wù)器上使用urlHttpConnection連接其他站點(diǎn)是允許的。

可以想象,你連接到你自己的服務(wù)器,打開一個頁面,如果這個頁面要獲取google的數(shù)據(jù),那么這個頁面可以向服務(wù)器發(fā)出請求(這個頁面和這個服務(wù) 器是同一個域,我通俗的理解,所以這個請求沒問題),服務(wù)器根據(jù)請求向google獲取數(shù)據(jù)(這個是允許的),然后服務(wù)器再將獲取到的數(shù)據(jù)反饋回頁面,這 樣頁面就獲取到google的數(shù)據(jù)了。

具體代碼怎么寫就不在話下啦!

最后可以通過服務(wù)器來解決這個問題,但至于為什么IE8可以允許跨域訪問我就不清楚了!

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

加料

轉(zhuǎn)自:http://www.cnblogs.com/accessking/archive/2012/05/12.html

在學(xué)習(xí)XMLHttpRequest的使用過程中,使用chrome打開任意空網(wǎng)頁,在控制臺下輸入如下代碼

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都出現(xiàn)了這種情況,但是使用IE8就不會出現(xiàn)這種錯誤,很多人不是很理解。

這里Windows help and support 做出了解釋 ?IE本身也并不是允許跨域的因?yàn)檫@樣很不安全,但是如果不跨域的話又帶來很多不便,所以會讓你手動的選擇一下是否允許跨域。而chrome、firfox、opera則默認(rèn)就是不允許。

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.


轉(zhuǎn)載于:https://blog.51cto.com/frabbit2013/1254709

總結(jié)

以上是生活随笔為你收集整理的Origin null is not allowed by Access-Control-Allow-Origin 解决方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。