我非常新的ajax。 试图通过tutorial如何在ajax事件上创建函数(onreadystatechange)
试图代码来理解:
<DOCTYPE html PUBLIC" ..//w3c//DTDXHTML 1.0 strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>ajax</title>
<script language="javascript" type="text/javascript">
xmlhttp = new XMLHttpRequest();
function getScores() {
xmlhttp.onreadystatechange() = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('scores').innerHTML = xmlhttp.responseText;
} else {
document.getElementById('scores').innerHTML = "<strong>Sonal Goyal</strong>"
}
}
xmlhttp.open("GET", "https://www.learntoprogram.tv/baseball.php", true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="score"></div>
<input type="button" value="get scores!" onclick="getScores()" />
</body>
</html>
我缺乏在哪里?
首先取代“分数”与“分”或周围的其他方法 – Manu