简体   繁体   English

Access-Control-Allow-Origin不允许使用Origin null(同步,无jQuery)

[英]Origin null is not allowed by Access-Control-Allow-Origin (Synchronous, no jQuery)

The first thing I would like to say is that I looked around for an answer to this for quite some time, but everything I found was about jQuery. 我想说的第一件事是,我在相当长的一段时间内一直在寻找答案,但是我发现的一切都是关于jQuery的。 This is not about jQuery. 这与jQuery无关。

I have some code (below), but when I ran it in Firefox then Firebug gave me this big, incomprehensible exception. 我有一些代码(如下),但是当我在Firefox中运行它时,Firebug给了我这个大的,难以理解的异常。 I tried it in Google Chrome and got something a bit more useful: "XMLHttpRequest cannot load http://www.wikipedia.org/ . Origin null is not allowed by Access-Control-Allow-Origin." 我在Google Chrome浏览器中进行了尝试,得到了一些更有用的信息:“ XMLHttpRequest无法加载http://www.wikipedia.org/。Access-Control-Allow-Origin不允许使用Origin null。” (If you'd like to know why I was trying to access Wikipedia, I often use it as a test site.) Here is my code: (如果您想知道为什么我要尝试访问Wikipedia,我经常将其用作测试站点。)这是我的代码:

function requestSite(url) {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET", url, false);
    xmlhttp.send();
    return xmlhttp;
}

All I tried to do with it was access Wikipedia. 我要做的只是访问Wikipedia。 Then Google, which gave me the same result. 然后是Google,它给了我相同的结果。 Perhaps it is worth noting that when I triggered the function with a button on the page, it gave me this, while using the console was exactly the same, but without the error message. 也许值得注意的是,当我使用页面上的按钮触发功能时,它给了我这个,而使用控制台却完全相同,但是没有错误消息。 Another thing that may or may not be worth mentioning is that I was running this file from my local filesystem. 另一件事可能或可能不值得一提的是,我是从本地文件系统运行此文件的。

You can't make an AJAX request to a URL that is on a different domain. 您无法向其他域中的URL发出AJAX请求。 It's a basic browser security issue. 这是基本的浏览器安全问题。

This error message means 此错误消息表示

"You are running this request from your local system". “您正在从本地系统运行此请求”。

Making ajax requests to some other domain besides the one you are running the code is (of course) not allowed. (当然)不允许向除您正在运行代码的域之外的其他域发出ajax请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Access-Control-Allow-Origin不允许使用Chrome Origin null - Chrome Origin null is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin不允许使用null - Origin null is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin 不允许来源 null - Origin null is not allowed by Access-Control-Allow-Origin 无法与jsonp配合使用的Access-Control-Allow-Origin不允许使用Origin null - Origin null is not allowed by Access-Control-Allow-Origin not working with jsonp Access-Control-Allow-Origin不允许使用原点null - Origin null is not allowed by Access-Control-Allow-Origin Jquery (jfeed) - Access-Control-Allow-Origin 不允许来源 xxxxx - Jquery (jfeed) - Origin xxxxx is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin 不允许 Origin - Origin is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin不允许使用Origin? - Origin is not allowed by Access-Control-Allow-Origin? Access-Control-Allow-Origin不允许起源 - Origin is not allowed by Access-Control-Allow-Origin XMLHttpRequest无法加载http:// localhost:8089 / jquery。 Access-Control-Allow-Origin不允许使用原点null - XMLHttpRequest cannot load http://localhost:8089/jquery. Origin null is not allowed by Access-Control-Allow-Origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM