3

私は ajax を使用して div を介して echo にあるものを表示したいだけの非常に小さなコードを作成しましたが、 echo にあるものではなく php スクリプト全体を表示します。誰かが私を助けてくれますか?

<html>
<script type="text/javascript" >
function test() {   
xmlHttp=new XMLHttpRequest();   
if (xmlHttp !== null) {
  xmlHttp.onreadystatechange=function() {
     if(xmlHttp.readyState==4 && xmlHttp.status==200) {
        var response = xmlHttp.responseText;
                alert("Match");
                alert(response);
                document.getElementById('show').innerHTML = response;
             }           
     }
  }
  xmlHttp.open("GET","try.php",true);
  xmlHttp.send(null);
 }
 </script>
<body>          
Enter answer: <input type="text" onKeyUp="test();"><br />
See returned value: <div id="show"></div>   
</body>
</html>

これは私のphpファイルです。エコーにあるものを出力するかどうかを確認したかったので、小さいです

<?php
 echo "i just want to see if this get's printed";
?>
4

1 に答える 1

1

ブラウザーの開発コンソールで [ネットワーク] タブを確認します。Chrome で F12 を押し、[ネットワーク] タブに移動してtest()関数を実行し、ネットワークの結果で適切な応答を確認します。結果は [Response] タブで確認できます。他のブラウザにも同様のコンソールが存在するはずです。

于 2013-09-14T07:09:30.800 に答える