2017-11-30 14 views
0

AJAXでボタントリガーでリクエストを送信しようとしていて、スパンエリアにレスポンスhtmlファイルがありました。ここで問題がどこにあるのかわかりません。コード:は私の最初のAJAXリクエストで問題が発生しました

//ajax.php

<html> 

<head> 
    <script type="text/javascript"> 
     function ajax() { 
      var xmlhttp; 

      //check the xml object comptbl 
      if (window.xmlHttpRequest) 
       xmlhttp = new XMLHttpRequest(); 
      else 
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 

      xmlhttp.onreadystatechange = function() 
      { 
      //check the request and make the response 
      if (xmlhttp.readyState == 4 & xmlhttp.status == 200) 

        document.getElementById("ajax").innerHTML = xmlhttp.responseText; 

      } 
      xmlhttp.open("GET", "info.html", true); 
      xmlhttp.send(); 


     } 

    </script> 
</head> 

<body> 
<span id="ajax"> 

    <!--response area --> 
</span> 

<button type="button" onclick="ajax()">make the request</button> 


</body> 


</html> 

//info.html

<html> 

    <head> 
     <title>the response file</title> 
    </head> 
    <style> 
     h1,h3 { 
      color: green; 
    font-family : 'ALGERIAN'; 

     } 



    </style> 

    <body> 

     <h1>WELCOME IM THE RESPONSE FROM THE SERVEUR</h1> 
     <h3>WITHOUT RELOAD THE WHOLE PAGE</h3> 


    </body> 

    </html> 
+1

ブラウザにエラーが要素コンソールを検査し得るかを働くことを願っていますか? PHPエラーが有効になっていますか?検査要素のネットワークタブにajaxリクエストのPHPエラーが表示されますか? – Goose

+0

あなたの 'info.html'には' '、' 'または' 'タグは含まれません。 – mulquin

+0

... 'xmlhttp.responseText'のために何を得るのかチェックしましたか、あるいはステータス200を打つことさえあったとしても、 – Jeff

答えて

1

変更この

にご//info.html
<style> 
    h1,h3 { 
     color: green; 
font-family : 'ALGERIAN'; 
    } 
</style> 


    <h1>WELCOME IM THE RESPONSE FROM THE SERVEUR</h1> 
    <h3>WITHOUT RELOAD THE WHOLE PAGE</h3> 

これは単純なテキスト応答を送信し、その後動作しない場合は...これは

関連する問題