How to make this code, via SetIntrerval, to access the file every 2 seconds?

params = "text=sens" request = new ajaxRequest() request.open("POST", "send.php", true) request.setRequestHeader("Content-type", "application/x-www-form-urlencoded") request.setRequestHeader("Content-length", params.length) request.setRequestHeader("Connection", "close") request.onreadystatechange = function () { if (this.readyState == 4) { if (this.status == 200) { if (this.responseText != null) { document.getElementById('message').innerHTML = this.responseText } else alert("Ошибка ajax Данные не получены") document.getElementById('warning').innerHTML = '<p>Ошибка ajax Данные не получены</p>'; } document.getElementById('warning').innerHTML = this.statusText } } request.send(params) function ajaxRequest() { try { var request = new XMLHttpRequest() } catch (e1) { try { request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e2) { try { request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e3) { request = false } } } return request 

}

    1 answer 1

    On jQuery like that.

     setInterval(function () { $.post('send.php', {text: 'sens'}); }, 2000); 

    So, for a note, compare the number of code.

    • 2
      in my opinion, @Zow does the right thing, that teaching native javascript will not be superfluous. - LeD4eG
    • one
      I have nothing against, offered an option. - Oleg