Code has been added to clipboard!
Interactive AJAX Polling
Example
<html>
<head>
<script>
function get_votes(int) {
if (window.XMLHttpRequest) {
// script for browser version above IE 7 and the other popular browsers (newer browsers)
xmlhttpreq = new XMLHttpRequest();
} else {
// script for the IE 5 and 6 browsers (older versions)
xmlhttpreq = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttpreq.onreadystatechange = function() {
//check if server response is readyÂ
if (this.readyState == 4 && this.status==200) {
document.getElementById("ajax_poll").innerHTML=this.responseText;
}
}
xmlhttpreq.open("GET","poll_votes.php?res="+int,true);
xmlhttpreq.send();
}
</script>
</head>
<body>
<div id="ajax_poll">
<h3>Is Bitdegree Learn a good learning platform?</h3>
<form>
Yes!
<input type="radio" name="res" value="0" onclick="get_votes(this.value)">
<br>No!
<input type="radio" name="res" value="1" onclick="get_votes(this.value)">
</form>
</div>
</body>
</html>