i am trying to read data every three seconds without reloading the page. I am missing something in my script because it doesn't refresh data until i reload the page. Thanks in advance.
<html>
<head>
<meta charset="UTF-8">
<title>Testing</title>
<!-- below script is for jquery -->
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">
function refreshData(){
$.ajax({
url: 'localhost/index1.php',
type:"POST",
data:"dataPost",
success: function(data){
document.getElementById("dataPost").innerHTML = data;
//render the dynamic data into html
}
});
}
setInterval(refreshData, 3000);
</script>
</head>
<div id="dataPost">
<?php
$conn = mysql_connect('localhost','user','password');
$db = mysql_select_db('db',$conn);
$query = "select * from table";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
echo $row['data1']."<br/>";
}
?>
</div>
</html>