javascript - Storing the value of variable in JS -


since main language c, used pointers , love them. have project need finish in javascript , i've got problem don't know how solve.

i want store value of variable got request. have script send php page, sends daemon written in c. when string wanted, use length measure size of string got , in next request want send number of bytes got url parameter.

window.onload = function() {   if (bytes === undefined) {     var bytes = 0;   }   var url = "/test/log.php?q=" + bytes;    function httpget(url) {     var xhttp = new xmlhttprequest();     xhttp.open("get", url, true);     xhttp.onload = function(e) {       if (xhttp.readystate === 4) {         if (xhttp.status === 200) {           console.log(xhttp.responsetext);           var option = "";           obj = json.parse(xhttp.responsetext);           (var key in obj) {             option += obj[key];           }            document.getelementbyid("list").innerhtml = asdf;           bytes = option.length;         }       };       xhttp.onerror = function(e) {         console.error(xhttp.statustext);       }     };      xhttp.send();   }    var updateinterval = 2000;    function update() {     httpget(url);     settimeout(update, updateinterval);   }    update(); } 

so, focus on variable bytes. should have value 0 when script first time called, , after every loop (it loops every 2 seconds, didn't show loop in code) should have value of previous length of received string.

you need make sure add bytes param onto url in way changes each call rather once @ page load when 0.

window.onload = function() {    if (bytes === undefined) {      var bytes = 0;    }    var url = "/test/log.php?q=";      function httpget(url) {      var xhttp = new xmlhttprequest();      xhttp.open("get", url, true);      xhttp.onload = function(e) {        if (xhttp.readystate === 4) {          if (xhttp.status === 200) {            console.log(xhttp.responsetext);            var option = "";            obj = json.parse(xhttp.responsetext);            (var key in obj) {              option += obj[key];            }              document.getelementbyid("list").innerhtml = asdf;            bytes = option.length;          }        };        xhttp.onerror = function(e) {          console.error(xhttp.statustext);        }      };        xhttp.send();    }      var updateinterval = 2000;      function update() {      httpget(url + bytes);      settimeout(update, updateinterval);    }      update();  }


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -