Currently delving into the world of AJAX & JavaScript, I have a question for the knowledgeable individuals out there.
I am curious to know how I can transform the code below from an OnClick event to a timed event.
For instance, I would like to refresh the content of the "showlist" DIV every 5 seconds...
I am aware that posting working code is not permitted here, but sharing my non-functional code would only add to the confusion.
I am gradually grasping the basics and any help or advice would be greatly appreciated.
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("showlist").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","playlist.php?t=" + Math.random(),true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>Ajax Testing...</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<div id="showlist"></div>
</body>
</html>