0
var dataid=45;
listStations.push(data[i].ID);
$.getJSON("https://example.com/json?id=" + data[i].ID, function (parkDetay) {
       var getCapacity = 100 - (Math.round((100 / parkDetay[0].capacity) * parkDetay[0].emptyCapacity));
       nowCapacity = getCapacity;
       console.log(dataid);
       nearStations.push([dataid, nowCapacity, nowValue])
   });

I give a constant value before the json parenthesis begins.

dataid = 45;

or a dynamic variable

dataid = data[i].ID;

Both of them do not print with console.log in JSON and return "0".

What to do? It does not push the series as an extra

Zak
  • 6,976
  • 2
  • 26
  • 48
  • 3
    There's nothing wrong with `dataid` in the snippet you posted. Verify the callback is actually invoked; it sounds like it's not per your statement "It does not push the series as an extra" – junvar Apr 07 '21 at 18:16
  • Adding elements to alert or console or array. The dataid value is 0 in all three. – Kadir Çolak Apr 07 '21 at 18:18
  • There is no JSON in this question. JSON is a text format for storing and sending data. `parkDetay` is a JavaScript object that has been parsed from the JSON received from the request to example.com. So when you say "the json parenthesis begins" that doesn't make much sense. – Heretic Monkey Apr 07 '21 at 18:26
  • Is this code in a loop? See https://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example – Barmar Apr 07 '21 at 18:40

0 Answers0