title: Return XML value after loop
body: <p>I'm looping around a JS function after an AJAX call for XML. When I use return it is undefined, even if I do if (i==x.length) {return}. </p>
  
  <p>I would like the getInfo function to return the node values array. Which should be fairly simple, all of the code works apart from the return part.</p>
  
  <pre><code>var myFunction = {
  sendAjax: function (url, success) {
              var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
              xhr.open('POST', url);
              xhr.onload = function () {
                  if (xhr.readyState &gt; 3 &amp;&amp; xhr.status == 200) success(xhr.responseXML);
              };
              xhr.send();
              return xhr;
          },
  
  getInfo: function () {
              myFunction.sendAjax('XXXXXXXXX', function (data) {
                  var i;
                  var xmlDoc = data
                  var x = xmlDoc.getElementsByTagName("Session");
                  var sessions = [];
  
                  for (i = 0; i &lt; x.length; i++) {
                      sessions[i] += xmlDoc.getElementsByTagName("XXXX")[i].childNodes[0].nodeValue + ","
  
              console.log(sessions[i]);
  
            }
  
                      return sessions;
  
                  });
              }
     }
  
  myFunction.getInfo(function(value){ 
    console.log('mylog=' + value);
    alert(value);
  });
  </code></pre>
  
  <p>Result comes back as undefined, it IS looping around and returning the values fine, but the return is returning before the loop is finished. I have tried doing an if statement i.e. if (i==x.length) then return ... but that does not work.</p>