title: jQuery Return value undefined
body: <p>FIXED! THANKS! See "Corrected Code" below.</p>
  
  <p>The goal is to get data back from the dialog box. I have seen lots of articles, but could not get any of them to work, so I decided to use a web service to pass the data back and forth between the dialog box and the underlying page. </p>
  
  <p>All of the code is in place except the code that reads values coming back from the web service. I can see in the debugger that the data is being passed back, but when I return to the caller, the returned data is undefined. </p>
  
  <p>jQuery function getLocal calls AJAX, gets good data back, but when it returns to the function that calls it (verbListShow), the returned value is "undefined". </p>
  
  <p>This is all happening in an ASP.NET page that is written largely in jQuery, and opens a jQuery dialog box. </p>
  
  <pre><code>function getLocal(name) {
      $.ajax({
          type: "POST",
          async: false,
          url: "WebServices/FLSAService.asmx/GetLocalVariable",
          dataType: 'json',
          contentType: 'application/json; charset=utf-8',
          data: JSON.stringify({ name: name }),
          success: function (data) {
              var rtn = data.d;
              return rtn;
          }
      });
  }
  </code></pre>
  
  <p>The above code works, but when called, rtn is undefined. Here is the caller:</p>
  
  <pre><code>function verbListShow(dutyNumber) {
  
      $('#dlgDutyList').dialog({
          modal: true,
          show: "slide",
          width: 250,
          height: 250,
          open: function (event, ui) {
              setLocal("DUTYNUMBER", dutyNumber);
          },
          buttons: {
              "Select": function () {
                  var id = getLocal("VERBID"); // &lt;*** Returns undefined
                  var verb = getLocal("VERB"); // &lt;*** Returns undefined
                  $.ajax({
                      type: "POST",
                      async: false,
                      url: "WebServices/FLSAService.asmx/SetDuty",
                      dataType: 'json',
                      contentType: 'application/json; charset=utf-8',
                      data: JSON.stringify({ dutyNum: dutyNumber, id: id, verb: verb }),
                      success: function (data) {
                          data = $.parseJSON(data.d);
                          if (data.ErrorFound) {
                              showMessage(data.ErrorMessage, 2, true);
                          }
                          else {
                              log('Set Duty: ' + data.StringReturn + ' (' + data.intReturn + ')');
                          }
                      },
                      error: function (XMLHttpRequest, textStatus, errorThrown) {
                          alert("updateDuty: "
                              + XMLHttpRequest.responseText);
                      }
                  });
  
                  $(this).dialog("close");
              },
              Cancel: function () {
                  $(this).dialog("close");
              }
          }
  
      });
      $('#dlgDutyList').dialog('open');
  </code></pre>
  
  <p>FIXED CODE:</p>
  
  <pre><code>function getLocal(name) {
  var rtn = "";
      $.ajax({
          type: "POST",
          async: false,
          url: "WebServices/FLSAService.asmx/GetLocalVariable",
          dataType: 'json',
          contentType: 'application/json; charset=utf-8',
          data: JSON.stringify({ name: name }),
          success: function (data) {
              rtn = data.d;
          }
      });
  return rtn;
  }
  </code></pre>