title: After parsing xml I am getting undefined as a result
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13285770/keeps-saying-result-property-is-not-defined-why">Keeps saying result property is not defined. Why?</a>  </p>
  </blockquote>
  
  
  
  <p>I am parsing xml and what I want is to return xml after parsing it. The problem is that in my <code>getResult()</code> function <code>result</code> has a value of <code>undefined</code>. Why and how can I make it work?</p>
  
  <p>Here is my code</p>
  
  <pre><code>var result  = '';
  
  var Xml = {
  to      : null,
  from    : null,
  url     : null,
  
  init: function (fromaddress, toaddress, link) {
      from    = fromaddress;
      to      = toaddress;
      url     = link;
  
      this.requestXml();
      return this;
  },
  
  requestXml: function () {
      $.ajax({
          type: "GET",
          url: url,
          dataType: "xml",
          success: this.parseXml
      });
  },
  
  parseXml: function (xml) {
      console.log('xml: ' + $(xml));
      result = $(xml);
  },
  
  getResult: function () {
      console.log('Result: ' + Xml.result); //&lt;--- Here result has undefined value
      return result;
  }
  };
  </code></pre>