There is a function:

(function poll() { setTimeout(function() { $.ajax({ type: "GET", url: "/api/system", processData: true, dataType: 'text', cache: false, success: function (data, textStatus, request) { var system = jQuery.parseJSON(data); $(".uptime").var(system.uptime); $(".system-uptime").var(system.systemUptime); } }); }, 1000); })(); 

it receives data from JSON, processes and replaces the value in ".uptime" and ".system-uptime" . According to the idea, this happens every second, a value of 1000 (ms). What I get: I receive data, it appears on the web page, but it does not update every second, although this function is called in the console. How to solve this problem? Is it possible to get around all this in the similarity:

 (function poll() { setTimeout(function() { $.ajax({ type: "GET", url: "/api/system", processData: true, dataType: 'text', cache: false, success: function (data, textStatus, request) { var system = jQuery.parseJSON(data); $("input[id='uptime']").val(system.uptime); $("input[id='sysUptime']").val(system.systemUptime); } }); }, 1000); })(); 

however, not with input.

  • Just in case, I will clarify: in the first block of code, you have .val instead of .val . Isn't that the problem? - Dmitriy Simushev
  • @DmitriySimushev is not, the problem is not this - Insider

1 answer 1

 setTimeout() -- функция вызываеться один раз, через заданный промежуток времени Вам нужно использовать функцию setInterval() 
  • data is not displayed. replaced by .val - the same. - Insider
  • Look in the console, data come in every second? - Sergei Stralenia
  • yes, data comes every second - Insider
  • Now just try to change the data in the console. $ ('. uptime'). val ('Blablabla'); And you have an input field with the class uptime or with id? Judging by the second example, you have id = uptime. Then you have to do $ ('# uptime'). Val ('Blalala') - Sergei Stralenia
  • I can't check now. example with ID; was written only as an example, it is missing from the code. - Insider