简体   繁体   English

Access-Control-Allow-Origin不允许使用Origin null。

[英]Origin null is not allowed by Access-Control-Allow-Origin.

I browse the answer for this question, but haven't find a good answer for me yet. 我浏览了该问题的答案,但尚未找到适合我的好答案。

var request = new XMLHttpRequest();
request.onreadystatechange = function(){
    if(request.readyState == 4 && request.status == 200){
        var response = response.responseText;
        window.open(response, "_blank", "location = 0, menubar = 0");
    }
}
request.open("POST",  "http://localhost/save.php", true)
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("imag="+data);

the above is my javascript code. 以上是我的JavaScript代码。 I did use http:// instead of file://, and I did put the files on XAMPP server. 我确实使用http://而不是file://,并且确实将文件放在XAMPP服务器上。 I also use header('Access-Control-Allow-Origin: *') in my save.php as someone mentioned, but I still get the same error. 我也提到过在save.php中使用header('Access-Control-Allow-Origin:*'),但仍然出现相同的错误。

Some help please... 请帮忙...

I finally get it. 我终于明白了。 When they say using http to open the file, they mean 2 things. 当他们说使用http打开文件时,它们表示两件事。

  1. in javascript's open method, use http to open. 在javascript的open方法中,使用http打开。 I did this. 我做到了
  2. in the browser, also use http. 在浏览器中,也使用http。 I didn't do this. 我没做 before, I just double click the file and it opens in chrome by File:// ...., I need to open the file in chrome manually by typing in http:// .... 之前,我只需双击该文件,即可通过File:// ....在chrome中打开,我需要通过输入http:// ...手动在chrome中打开文件。

Silly mistakes... 愚蠢的错误...

暂无
暂无

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

相关问题 Access-Control-Allow-Origin不允许起源。 - Origin is not allowed by Access-Control-Allow-Origin. 在android web视图中,Access-Control-Allow-Origin.:1不允许使用null? - Origin null is not allowed by Access-Control-Allow-Origin.:1 in android web view? “Access-Control-Allow-Origin不允许使用Origin null。”使用jQuery调用Web服务时出错 - “Origin null is not allowed by Access-Control-Allow-Origin.” Error when calling a web service with jQuery Valums文件上载器给出“ Access-Control-Allow-Origin不允许使用Origin null。”错误 - Valums file uploader giving an “Origin null is not allowed by Access-Control-Allow-Origin.” error XMLHttpRequest无法加载http:// localhost:8081 / sample.xml。 Access-Control-Allow-Origin不允许使用null。 - XMLHttpRequest cannot load http://localhost:8081/sample.xml. Origin null is not allowed by Access-Control-Allow-Origin. XMLHttpRequest无法加载http://ideone.com/api/1/service.wsdl。 Access-Control-Allow-Origin不允许使用Origin null。 - XMLHttpRequest cannot load http://ideone.com/api/1/service.wsdl. Origin null is not allowed by Access-Control-Allow-Origin. Access-Control-Allow-Origin不允许Angularjs Rails- Origin http:// localhost:9000。 - Angularjs Rails- Origin http://localhost:9000 is not allowed by Access-Control-Allow-Origin. XMLHttpRequest无法加载“此URL”来源Access:Control-Allow-Origin不允许使用原始http:// localhost:3000。 - XMLHttpRequest cannot load “THIS URL” Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin. Access-Control-Allow-Origin不允许使用http://0.0.0.0:4567。 与骨干和Firebase - http://0.0.0.0:4567 is not allowed by Access-Control-Allow-Origin. with Backbone & Firebase Access-Control-Allow-Origin不允许使用Chrome Origin null - Chrome Origin null is not allowed by Access-Control-Allow-Origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM