title: ajax call web service: return undefined
body: <p>I have a jquery ajax call asp.net web service but it is not working. I got an error:</p>
  
  <p><strong>isValid is underfined.</strong></p>
  
  <p>I set a breakpoint and found that the code never reaches web service.
  Jquery:</p>
  
  <pre><code>&lt;script src="../jquery-1.7.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script&gt;
      function ValidateUserName() {
          var isValid;
          $.ajax({ type: "POST",
              url: "UserNameWebService.asmx/ValidateUserName",
              data: "{'strUsername': '" + $("#&lt;%=TextUserName.ClientID%&gt;").val() + "'}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              async: false,
              success: function (data) {
                  isValid = data;
              }
          });
           return isValid;
          } 
  &lt;/script&gt;
  </code></pre>
  
  <p>web service code:</p>
  
  <pre><code> [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.ComponentModel.ToolboxItem(false)]
  // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
  [System.Web.Script.Services.ScriptService]
  public class UserNameWebService : System.Web.Services.WebService
  {
  
      [WebMethod]
      public bool ValidateUserName(string strUsername)
      {
          \\ then return something by logic
  </code></pre>
  
  <p>Thank you.</p>