title: PHP refresh data every 3 second using javascript
body: <p>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.</p>
  
  <pre><code>&lt;html&gt;
     &lt;head&gt;
         &lt;meta charset="UTF-8"&gt;
         &lt;title&gt;Testing&lt;/title&gt;       
        &lt;!-- below script is for jquery --&gt; 
         &lt;script type="text/javascript" src="js/jquery-1.4.2.js"&gt;&lt;/script&gt;
         &lt;script type="text/javascript"&gt;
             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);
             &lt;/script&gt;
     &lt;/head&gt;
     &lt;div id="dataPost"&gt;
     &lt;?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']."&lt;br/&gt;";
         }
     ?&gt;
     &lt;/div&gt;    
  &lt;/html&gt;
  </code></pre>