search

Home  >  Q&A  >  body text

Ajax returns data, could you guys please check what is wrong? ?

<!------页面点击后,ajax脚本从PHP文件返不了数据,改变不了页面h2标签的内容------------->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</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文件内容
<?php
echo '欢迎来到php中文网';

?>
*/
</script>
</html>


过客过客2207 days ago1196

reply all(3)I'll reply

  • 失去过去

    失去过去2019-02-05 20:14:06

    You wrote the wrong tag

    var btn=document.getElementsByTagName('botton')[0];

    button is not botton

    reply
    0
  • 过客

    Thank you for your advice. If I look closely, the label is indeed wrong. After changing it, the test came out. When I was writing, I couldn't even see this low-level mistake...

    过客 · 2019-02-05 23:25:13
  • Cancelreply