title: How to use variable from one method in another?
body: <p>How to use site variable value from <code>onreadystatechange</code> method in soap method?</p>
  
  <p>My code:</p>
  
  <pre><code>soap(value) {
    var siteValue = '';
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', 'URL', true);
    var to_json = require('xmljson').to_json;
    var sr = xyz
  
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
          soapres = xmlhttp.responseText;
          this.soapresponse(soapres);
  
          to_json(soapres, function(error, data) {
            var a = data['soapenv:Envelope']['soapenv:Body']['wss:readResponse']['readReturn']['resultXml']['_'];
            var jsonR = JSON.parse(a);
            var sitee = jsonR.SALFCY; //site
            siteValue = JSON.stringify(sitee);
            alert(siteValue);
          });
        }
      }
    }
  }
  </code></pre>