<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="text" value="test">
<input id="submit_button" type="button" value="submit">
<p id="prompt">test
<script>
function sendData()
{
console.log("it is a test");
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("post", "test.php",true);
xmlHttp.send("iq=test");
xmlHttp.onreadystatechange = function(){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
document.getElementById("prompt").innerHTML = xmlHttp.responseText;
}
}
}
ob = document.getElementById("submit_button");
ob.addEventListener("click",sendData);
</script>
</body>
</html>
test.php is as follows
<?php
echo "it is a test";
?>
after clicking button, I found that console.log ("it is a test"); was not running.
excuse me, what is the reason for this?