簡體   English   中英

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

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

我瀏覽了該問題的答案,但尚未找到適合我的好答案。

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);

以上是我的JavaScript代碼。 我確實使用http://而不是file://,並且確實將文件放在XAMPP服務器上。 我也提到過在save.php中使用header('Access-Control-Allow-Origin:*'),但仍然出現相同的錯誤。

請幫忙...

我終於明白了。 當他們說使用http打開文件時,它們表示兩件事。

  1. 在javascript的open方法中,使用http打開。 我做到了
  2. 在瀏覽器中,也使用http。 我沒做 之前,我只需雙擊該文件,即可通過File:// ....在chrome中打開,我需要通過輸入http:// ...手動在chrome中打開文件。

愚蠢的錯誤...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM