title: AJAX autocomplete with jQuery in ASP.Net
body: <p>I am trying to implement AJAX autocomplete in ASP.Net using jQuery. This is my table definition:</p>
  
  <pre><code>CREATE TABLE [dbo].[tbluser](
      [nid] [int] IDENTITY(1,1) NOT NULL,
      [name] [varchar](100) NULL,
      [email] [varchar](100) NULL,
      [address] [varchar](200) NULL,
      [password] [varchar](100) NULL
  )
  </code></pre>
  
  <p>My Webpage i.e. Autocomplete.aspx</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /&gt;
      &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          $(function () {
              $("#superheroz").autocomplete({    
                  source: function (request, response) {
                      $.ajax({
                          type: "POST",
                          contentType: "application/json; charset=utf-8",
                          url: '&lt;%=ResolveUrl("Autocomplete.aspx/binddata") %&gt;',
                          dataType: "json",
                          data: "{ 'name': '" + request.term + "'}",
                          success: function (data) {
                              response(data.d);
                          },
                          error: function (result) {
                              alert(response.responseText);
                          },
                          failure: function () { 
                              response.responseText   
                          }
                      });
                  }
              });
          });
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
          &lt;div&gt;
              &lt;input type="text" id="superheroz" runat="server" /&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>And This is the Webmethod I created in Autocomplete.aspx.cs</p>
  
  <pre class="lang-csharp prettyprint-override"><code>[WebMethod]
  public List&lt;string&gt; binddata(string name)
  {
      List&lt;string&gt; ud = new List&lt;string&gt;();
      string sql = "select * from tbluser where name like '%" + name + "%'";
      ds = new DataSet();
      ds = da.getData(sql);
      if (ds.Tables[0].Rows.Count != 0)
      {
          foreach (DataRow dr in ds.Tables[0].Rows)
          {
              string su;
              su = dr["name"].ToString();
              ud.Add(su);
          }
      }
  
      return ud;
  }
  </code></pre>
  
  <p>Now this produces an alert which says 'unknown'. Please help.</p>