简体   繁体   中英

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. I did use http:// instead of file://, and I did put the files on XAMPP server. I also use header('Access-Control-Allow-Origin: *') in my save.php as someone mentioned, but I still get the same error.

Some help please...

I finally get it. When they say using http to open the file, they mean 2 things.

  1. in javascript's open method, use http to open. I did this.
  2. in the browser, also use 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:// ....

Silly mistakes...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM