Home > OS >  None response from a function http in JS
None response from a function http in JS

Time:07-11

I'm coding a request HTTP in a JS function, but it not work (none message in console, none response, none data). Though, is not my first time in request HTTP, but I not find the error i n my code. Can you enlighten me ? Here is my code :

function dmd_art(){
  var httpRequest = getHttpRequest();
  httpRequest.onreadystatechange = function () {
    if (httpRequest.readyState === 4){
      document.getElementById('annimation_loader').style.display = 'none';
      document.getElementById('aff_pub').innerHTML = httpRequest.responseText;
    }  
  }
  httpRequest.open('GET', 'includes/article.php', true)
}

getHttpRequest() is a function to adapted XMLHttpRequest to all web browsers

CodePudding user response:

function dmd_art(){
  var httpRequest = getHttpRequest();
  httpRequest.onreadystatechange = function () {
    if (httpRequest.readyState === 4){
      document.getElementById('annimation_loader').style.display = 'none';
      document.getElementById('aff_pub').innerHTML = httpRequest.responseText;
    }  
  }
  httpRequest.open('GET', 'includes/article.php', true)
  httpRequest.send(/* If there're some data send here */); // Add this
}

Yeah, missing something right? If you don't send the request, that does nothing.

  • Related