onreadystatechange未定义错误

onreadystatechange undefined error

本文关键字:错误 未定义 onreadystatechange      更新时间:2023-09-26

一个多小时以来,我一直在尝试调试我的代码,但没有成功。我意识到ajax的异步调用意味着我必须使用onreadystatechange事件的回调函数。问题是,我在控制台中不断收到"UncaughtTypeError:undefined不是函数xmlhttp.onreadystatechange"的消息。我的代码出了什么问题?我正在遵循上的模板http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_suggest_php我看不出有什么不同。

window.onload = function() {
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				var obj = JSON.parse(xmlhttp.responseText);
				document.getElementbyId("table").innerHTML = "Test";
			}
		}
		xmlhttp.open("GET", "bookstore.php?filename=bookstore.json", true);
		xmlhttp.send();
   }

我看到的唯一问题是getElementbyId应该是getElementById(大写B