node.js - Javascript value doesn't change when the variable contained in it increases -


i have program in node.js. connects web service offers json file data, file shows limited amount of data (500 records per request), starting value of index parameter in request. "lastentry" returns id of last record current page of data. lastpage boolean indicates when last page reached.

the first request looks this: http://example.com/data.json?index=0

i build function id of last record. calls until lastpage true. index variable increases correctly every request, according value read json, "url" doesn't change , stays @ 0, though built index variable. why that?

var lastpage = false; var index = 0; var url = "http://example.com/data.json?index=" + index;  function getlastentry() {     request(url, function (err, resp, body) {         if (err || resp.statuscode != 200) {             // error handling         } else {             var data = json.parse(body);             index = data.lastentry;             lastpage = data.lastpage;              if (lastpage == false) {                 getlastentry();             }         }     } }  getlastentry(); 

that's not way javascript works. once you've initialized variable "url", initialization expression never computed again. can arrange happen each time call "request" moving computation there:

var url = "http://example.com/data.json?index=";  function getlastentry() {     request(url + index, function (err, resp, body) { 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -