开发者

Ajax update for jQuery

开发者 https://www.devze.com 2023-04-08 12:17 出处:网络
I\'ve got some very large data tables and I\'m trying to make an automatic updater with jQuery but it seems to make a lot of unnecessary databbase calls before it does the update. What I would like is

I've got some very large data tables and I'm trying to make an automatic updater with jQuery but it seems to make a lot of unnecessary databbase calls before it does the update. What I would like is to check just one variable "lastModified" and compare it to the column in the database that will change when the table changes.

What I have works, but I'd like to reduce the traffic. Any ideas?

function update(){
   var turl = "tracking?objId=";
   $.ajax({
      type: "GET",
      url: turl + source,
      success: function(data){
         $("#summary").html(data)
       }
   });
 开发者_运维问答} var holdTheInterval = setInterval(update, 60000);

(this is the basic code that does a nice job updating)

EDIT I've solved this problem by using a separate jsp page with only an input containing the lastModified date, and on the page with the data tables, I've put another lastModifed input. I run the update() on the new jsp page, then compare the inputs. If they're different, I run the full update. This process works much better


Currently you're polling only once per 10 hours, so I doubt someone will notice this. I'd say you can remove this ajax polling to reduce chance of getting more traffic, in case customer keeps browser open


How about writing a dedicated server side script that will only return the last Rev. No in the DB?

You can then

  • poll that script via AJAX every so often without causing an insane amount of traffic.
  • do if (local_rev !== remote_rev) { update(); }
0

精彩评论

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