php - Ajax Javascript Last data inserted -


i want last data inserted table in realtime, using ajax refresh data every 5 seconde. first of calling php script current last id, , place in variable "last" variable "last" undefined if global variable

 var last = 0; var ischanged =0; window.setinterval(function(){      alert(last);     $.post(         "controller/ajaxcomment.php",         { act: "getlastcommentid", id_post: params.id },          function(data) {             data = data.tostring();               if(ischanged == 0)             {                 last = data;                 ischanged = 1;             }            // alert("data" + data + "last" + last);             last = 3 ;             if(last != data)             {                 var last = data;                 $.post(                     "controller/ajaxcomment.php",                     {                         act:"getlastcomment" , id_post: params.id                     },                     function(info)                     {                         $("#result").append(info);                     }                 )             }          }     ); }, 5000); 

this because have 2 variables named last.

one global , 1 scoped in interval function var last = data;.

remove var 1 inside timer if want update global variable


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -