开发者

Javascript getting count from db continuosly

Hi there Everybody! I am facing a little issue. I have a DIV where I need to show the count of rows from the database. The problem is that when the page refresh the count is not still updated because the database mySQL takes a while, so开发者_StackOverflow中文版 I have to refresh the page again. Do you know how can I show the count of the rows maybe with javascript? In a way that the count of the rows will be continuosly checked and updated without page reloading.. If I need jQuery for this, just to let you know I am on version 1.3.2 Let me know! Thanks so much!


yea sure, ajax it... first, it does sound odd that when u refresh the page the database isnt ready, but lets assume there is a sync issue where db gets updated out of sync with the current page... the solution is ajax

function doCountUpdate(){
$.get("url_to_return_count",function(data){
    assuming the returned data is a number
    $("#myDiv").text(data);
    setTimeout(doCountUpdate, 1000);
}
}


I think at page load, You can do that by simply a ajax call to a function and return the row and display it on a DIV.

$(document).ready(function() {
 // put all your jQuery goodness in here.
  $.ajax({
  url: "somepage.php",
  success: function(data){
    $('#div_id').text(data);
   }
 });

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜