2017-04-12 12 views
0

私は簡単なプログラムでphp-Ajaxをテストしたいです.htmlとphpファイルを使用していますが、両方とも同じディレクトリ(/ var/www/html) 。ボタンをクリックすると、コンソールに次のエラーが表示されます。 XML解析エラー:ルート要素が見つかりません。 ??XML構文解析エラー:ルート要素が見つかりません位置(php + Ajax)

htmlファイル

<html> 
    <head> 
     <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> 
     <meta content="utf-8" http-equiv="encoding"> 
     <title> Ajax testing </title> 
     <script type="text/javascript"> 
      function load(){ 
        var xmlhttp = new XMLHttpRequest(); 
        xmlhttp.onreadystatechange = function() { 
        if (this.readyState == 4 && this.status == 200) { 
         document.getElementById("result").innerHTML = this.responseText; 
        } 
       }; 
       xmlhttp.open("GET", "simple.php" , true); 
       xmlhttp.send(); 
      } 
     </script> 
    </head> 
    <body> 
     <button onclick="load();">Click here</button> 
     <div id="result"> </div> 
    </body> 
</html> 

PHPファイルは

<?php 
    echo "Hello"; 
?> 

このコードで何が間違っているのですか?

答えて

0

このスレッドは、スレッドからそれxmlhttprequest for local files

について説明します。

Historically, you can't query for local files from JavaScript (or shouldn't be allowed to, or something's odd). This would be a serious breach of security.

There are only a few circumstances where you can do this, but in general they involve specific security settings requiring to be set for your browser, to either lift the limitation or to notify the current page's execution process that that is is granted this exceptional right. This is for instance doable in Firefox by editing the properties. It's also commonly OK when developing browser extensions (for instance for Chrome or FF) if they request the file access permissions.

私はApacheサーバをインストールし、その上で私のphpファイルを保存しました。私はそれが過度の過労であることを知っているが、ちょっと、それは働いた:)

関連する問題