title: jQuery deferred : use to delay return of function until async call within function complete + get return value
body: <p>How can I correctly use jQuery deferreds to delay return of function until async call within function complete + get return value?</p>
  
  <p>This is my current code:</p>
  
  <pre><code>function getFields(page)
  {
    var dff = $.Deferred();
    result = {};
    $.ajax( //the async call
      {
        url: page,
        success:
          function (data)
          {
            //work out values for field1 &amp; field 2 from data here
            result = 
            {
              'field1' : field1,
              'field2' : field2
            };
          },
        complete:
          function()
          {
            dff.resolve(result); //my attempt to return the result
          }
      }
    );
    return dff.promise();
  }
  </code></pre>
  
  <p>I want this to print {"field1":"value1","field2":"value2"}</p>
  
  <pre><code>var result = getFields('http://something');
  console.log(JSON.stringify(result)); 
  </code></pre>
  
  <p>However, the value of result appears to be a jQuery object - so I'm doing something wrong, but what?</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>P.S. Sorry for the newbie question, I am a first time user of deferreds, so I am still grasping the basic concepts.</p>