I need the recivedData variable that is declared at the beginning to store the value assigned to it in the function and show it outside the function

Asked

Viewed 12 times

0

   var recivedData;
    var obj, dbParam, xmlhttp;
    obj = { "table":"customers", "limit":100 };
    dbParam = JSON.stringify(obj);
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        recivedData=this.responseText;    
      }
    };
    xmlhttp.onreadystatechange 
    document.getElementById("demais").innerHTML = recivedData;

xmlhttp.open("GET", "reg.php", true); xmlhttp.send(); console.log(recivedData); var datasource=recivedData;

  • At this time she is returning Undefined

  • You are trying to access the value before it is available. You need to understand how asynchronous operations work.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.