title: Jquery Ajax Call, doesn't call Success or Error
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call-from-a-function">How do I return the response from an asynchronous call?</a>  </p>
  </blockquote>
  
  
  
  <p>I am using Jquery Ajax to call a service to update a value.</p>
  
  <pre><code>function ChangePurpose(Vid, PurId) {
      var Success = false;
      $.ajax({
          type: "POST",
          url: "CHService.asmx/SavePurpose",
          dataType: "text",
          data: JSON.stringify({ Vid: Vid, PurpId: PurId }),
          contentType: "application/json; charset=utf-8",
          success: function (data) {
              Success = true;//doesn't go here
          },
          error: function (textStatus, errorThrown) {
              Success = false;//doesn't go here
          }
  
      });
      //done after here
      return Success;
  }
  </code></pre>
  
  <p>and Service:</p>
  
  <pre><code>[WebMethod]
  public string SavePurpose(int Vid, int PurpId)
  {
      try 
      {
          CHData.UpdatePurpose(Vid, PurpId);
          //List&lt;IDName&gt; abc = new List&lt;IDName&gt;();
          //abc.Add(new IDName { Name=1, value="Success" });
          return "Success";
      }
      catch (Exception ex)
      {
          throw new Exception(ex.Message);
      }
  }
  </code></pre>
  
  <p>the service is being called Successfully from the AJAX. <strong>Value is also being Changed.</strong> But after the Service, <strong>success:</strong> or <strong>error:</strong> functions are <strong>not being called</strong>, in this case success should have been called but it is not working.</p>
  
  <p>I used firebug and found that, the success or error functions are being skipped and goes directly to <code>return Success;</code></p>
  
  <p>Can't seem to find what's the problem with the code.</p>
  
  <p><strong>Update:</strong>
  adding <code>async: false</code> fixed the problem</p>