title: How can I return a value from GM_xmlhttprequest?
body: <p>I have this code here:</p>
  
  <pre><code>var infiltrationResult;
  
  while(thisOption) {
      var trNode = document.createElement('tr');
      var tdNode = document.createElement('td');
      var hrefNode = document.createElement('a');
  
      infPlanetID = thisOption.getAttribute('value');
  
    var myURL = "http://www.hyperiums.com/servlet/Planetinf?securitylevel=90&amp;newinfiltr=New+infiltration&amp;planetid=" + PlanetID + "&amp;infplanetid=" + infPlanetID;
  
      GM_xmlhttpRequest({
          method: 'GET',
          url: myURL,
          headers: {
              'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
              'Accept': 'application/atom+xml,application/xml,text/xml',
          },
          onload: function(responseDetails) {
                  if (responseDetails.responseText.match(/&lt;b&gt;Invalid order&lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;BR&gt;&lt;center&gt;&lt;font color=#AAAA77 face=verdana,arial size=2&gt;The target planet is blocking all infiltrations[\s\S]&lt;BR&gt;&lt;BR&gt;/im)) {
                      // Successful match
                      infiltrationResult = 'Invalid Order';
                  } else {
                      // Match attempt failed
                      infiltrationResult = 'Infiltration Successfully Created';
                  }
          }
      });
  </code></pre>
  
  <p>When I add</p>
  
  <blockquote>
    <p>alert(infiltrationResult);</p>
  </blockquote>
  
  <p>right after it is assigned, I correctly see the string.</p>
  
  <p>However, after the function has exited, I have try the same alert and I get:</p>
  
  <pre><code>undefined
  </code></pre>
  
  <p>Any ideas what I'm doing wrong?</p>