By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,450 Members | 980 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,450 IT Pros & Developers. It's quick & easy.

Use jquery to retrieve a lot of data

P: 17
Hey guys I created this chat system that used to work fine till number of messages increased (over 300 messages and i want it to take up to 1000)started to cause slow script and takes time to retrieve all data. The idea depends on selecting the data XML style and then add it to a specific tab and repeat the act with setTimeout,is there any other way i can do i really need ideas and here is my code.
Expand|Select|Wrap|Line Numbers
  1.  function updateMessage()
  2.  {
  3.   $.post("db.php",
  4.   {MsgNo :$("#no_of_msgs").val()},
  5.   function(data)
  6.  {
  7.    $(data).find("message").each(function() {
  8.    var msg_id = $(this).find("msg_id").text();
  9.    var date_time = $(this).find("date_time").text();
  10.    var from_user = $(this).find("from_user").text();
  11.    var from_user_id = $(this).find("from_user_id").text();
  12.    var from_group = $(this).find("from_group").text();
  13.    var to_user = $(this).find("to_user").text();
  14.    var to_user_id = $(this).find("to_user_id").text();
  15.    var to_group = $(this).find("to_group").text();
  16.    var msg_type = $(this).find("msg_type").text();
  17.    var msg = $(this).find("msg").text();
  18.    var from_grp_abr = $(this).find("from_grp_abr").text();
  19.    var to_grp_abr = $(this).find("to_grp_abr").text();
  20.    var flagged = $(this).find("flagged").text();
  21.    var onlydate = getonlydate(date_time);
  22.    $("#no_of_msgs").val(msg_id);
  23.  
  24.    if (from_group == $("#login").val())
  25. {
  26.  var reply = '';
  27. }
  28. else {var reply = 'reply';}
  29.  
  30.    if(from_user == "")
  31.    {
  32.     var handle_reply = from_grp_abr;
  33.    }
  34.    else 
  35.    {
  36.     var handle_reply = from_user;
  37.    }
  38.  
  39.    var html = "<tr id='row_"+msg_id+"'>";
  40.    html += "<td><a class='bullet' onclick='changeStatus(\""+msg_id+"\")'>&nbsp;<\/a><\/td>";
  41.    html += "<td><a class='"+reply+"' onclick=\"reply('"+escape(handle_reply)+"','"+escape(to_user)+"',"+from_user_id+","+to_user_id+");\">  <\/a><\/td>";
  42.     html += "<td class='time'>"+date_time+"<\/td>";
  43.      html += "<td>"+from_user+"&nbsp;["+from_grp_abr+"]"+"<\/td>";
  44.      html += "<td>"+to_user+"&nbsp;["+to_grp_abr+"]"+"<\/td>";
  45.      html += "<td><a href='#' class="+msg_type+"><\/a><\/td>";
  46. html += "<td><a id='flag_"+msg_id+"' class='"+class_flag+"' onclick='flagMsg("+msg_id+")'>  <\/a><\/td>";
  47.          html += "<td>"+msg+"<\/td>";
  48.          html += "<td>"+from_grp_abr+"<\/td><\/tr>";
  49.  
  50.            $('#no_of_msgs').val(msg_id);
  51.  
  52.   $("#tbody1").prepend(html);
  53. updatetabledata('t1');
  54. alternateRows('t1');
  55.  //append data to tab2 messages received
  56.     if (to_group == $("#login").val())
  57.     {
  58.          $("#tbody2").prepend(html);
  59.          updatetabledata('t2');
  60.          alternateRows('t2');
  61.       }
  62.    //append data to tab3 sent messages
  63. else if (from_group == $("#login").val())
  64.    {
  65.    $("#tbody3").prepend(html);
  66.    updatetabledata('t3');
  67.    alternateRows('t3');
  68.   }
  69.  
  70.    if(from_group != $("#login").val())
  71.   {
  72.    $("#tbody"+from_group).prepend(html);
  73.    updatetabledata('t'+from_group);
  74.    alternateRows('t'+from_group);
  75.   }
  76.    if(to_group != $("#login").val())
  77.   {
  78.    $("#tbody"+to_group).prepend(html);
  79.    updatetabledata('t'+to_group);
  80.    alternateRows('t'+to_group);    
  81.   }
  82.     });
  83.  });
  84.    setTimeout('updateMessage()',3000); 
  85.  }
  86.  
I am thinking the problem is for using each() and then distributing the data over several tabs at same time any ideas.
Apr 13 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.