0

次の回答に基づいて作成した次のページ ウィッチがあります:サーバー ファイルを javascript で読み取ります が、機能しません。そして、エラーを警告します。私は次のものを持っています:

<!DOCTYPE html>
<html>
  <head>
    <script>

      function getFileFromServer(url, doneCallback) {
    var xhr;

    xhr = new XMLHttpRequest();
    xhr.onreadystatechange = handleStateChange;
    xhr.open("GET", url, true);
    xhr.send();

    function handleStateChange() {
        if (xhr.readyState === 4) {
            doneCallback(xhr.status == 200 ? xhr.responseText : null);
        }
    }
}

  getFileFromServer("http://10.10.10.24/DataInfo.txt", function(text) {
    if (text === null) {
        // An error occurred
        alert("error");
    }
    else {
        alert("good");
        alert(text);
        // `text` is the file text
    }
});

    </script>
  </head>
  <body>
  </body>
</html>

更新: 私の IP アドレスは10.10.10.24、ブラウザ経由でリンクにアクセスできますhttp://10.10.10.24/DataInfo.txt

4

1 に答える 1

0

XMLHttpRequest を使用して、独自のドメインからのみページをロードできます。それがセキュリティ機能です。

于 2013-05-24T18:30:48.670 に答える