<!------頁(yè)面點(diǎn)擊后,ajax腳本從PHP文件返不了數(shù)據(jù),改變不了頁(yè)面h2標(biāo)簽的內(nèi)容-------------> <!doctype html> <html> <head> <meta charset="utf-8"> <title>無(wú)標(biāo)題文檔</title> </head> <body> <button>歡迎詞</button> <h2></h2> </body> <script> var btn=document.getElementsByTagName('botton')[0]; btn.onclick=function (){ var xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=function (){ if(xmlhttp.readyState==4 && xmlhttp.status==200){ var ht=document.getElementsByTagName('h2')[0]; ht.innerHTML=xmlhttp.responseText; } } xmlhttp.open('get','test.php',true); xmlhttp.send(); } /* //這里是php文件內(nèi)容 <?php echo '歡迎來(lái)到php中文網(wǎng)'; ?> */ </script> </html>
你標(biāo)簽寫錯(cuò)了?
var?btn=document.getElementsByTagName('botton')[0];
button 不是 botton
?