Problem with AJAX



  • How do you do, this code, through SetIntrerval, what would the file be once 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



  • Here. jQuery Okay.

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

    All right, for the record, compare the code.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2