0

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...

user2628641
  • 2,035
  • 4
  • 29
  • 45
  • try specifying the filename without the ```http://localhost``` – sahbeewah Jul 10 '14 at 22:57
  • Which browser are you testing in? Is there a web server running on localhost? What is the URL of the page you are trying to run this from? – jfriend00 Jul 10 '14 at 22:58
  • Potentially related answer: http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin?rq=1 – jfriend00 Jul 10 '14 at 23:00
  • Change the asterisk `*` to your domain - `http://localhost` in your case – hex494D49 Jul 10 '14 at 23:03

1 Answers1

0

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...

user2628641
  • 2,035
  • 4
  • 29
  • 45