Показать сообщение отдельно
  #2 (permalink)  
Старый 26.02.2018, 11:40
Аватар для Aetae
Тлен
Отправить личное сообщение для Aetae Посмотреть профиль Найти все сообщения от Aetae
 
Регистрация: 02.01.2010
Сообщений: 6,597

Попробуйте так:
strLED1 = "";
function GetArduinoIO()
{
  nocache = "&nocache=" + Math.random() * 1000000;
  var request = new XMLHttpRequest();
  request.onreadystatechange = function()
  {
    if (this.readyState == 4) {
      if (this.status == 200) {
        if (this.responseXML != null) {

          var count;

          if (this.responseXML.getElementsByTagName('LED')
              [0].childNodes[0].nodeValue === "checked") {
            document.LED_form.LED1.checked = true;
          }
          else {
            document.LED_form.LED1.checked = false;
          }
        }
      }
      setTimeout(GetArduinoIO, 1000);
    }
  }
  request.open("GET", "ajax_inputs" + strLED1 + nocache, true);
  request.send(null);
  strLED1 = "";
}

function GetCheck()
{
  if (LED_form.LED1.checked) {
    strLED1 = "&LED1=1";
  }
  else {
    strLED1 = "&LED1=0";
  }
}
Суть в том, что тут запрос будет выполняться не каждую секунду, а через секунду после ответа.
__________________
29375, 35
Ответить с цитированием