title: JQUery autocomplete in ASP.Net Webservice
body: <p>This is driving me crazy , I just keep getting the message "error" nothing else. I had this autocomplete working with AJAX Toolkit, but I want to try JQuery, I have very little experience with JQuery.  Here is WebService code:</p>
  
  <pre><code>  [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // 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 WebService : System.Web.Services.WebService {
  
  public WebService () {
  
      //Uncomment the following line if using designed components 
      //InitializeComponent(); 
  }
  
  [WebMethod]
  public static string GetNames(string prefixText, int count)
  {
      Trie ArtistTrie = new Trie();
      if (HttpContext.Current.Cache["CustomersTrie"] == null)
      {          
          SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
          SqlCommand comm = new SqlCommand();
          comm.CommandText = "SELECT * FROM TopArtists ORDER BY name ASC";
          SqlDataAdapter da = new SqlDataAdapter();
          DataTable dt = new DataTable();            
          da.SelectCommand = comm;
          comm.Connection = conn;
          conn.Open();
          da.Fill(dt);
          conn.Close();
          Trie newtrie = new Trie();
          foreach (DataRow dr in dt.Rows)
          {
              // topartists.Add(dr[0].ToString());
              newtrie.Add(dr[0].ToString());
          }
          HttpContext.Current.Cache["CustomersTrie"] = newtrie;
      }
       ArtistTrie = (Trie)HttpContext.Current.Cache["CustomersTrie"];
  
       List&lt;string&gt; list = ArtistTrie.GetCompletionList(prefixText, 10);
       List&lt;Band&gt; list1 = new List&lt;Band&gt;();
       foreach (string a in list)
       {
           Band newband = new Band();
           newband.Name = a;
           list1.Add(newband);
       }
       string json = JsonConvert.SerializeObject(list1, Formatting.Indented);
       return json;
  
  }
  </code></pre>
  
  <p>Here is JQuery Code:</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
        $(document).ready(function () {
          $(function () {
             $("#tb1").autocomplete({
  
          source: function (request, response) {
              $.ajax({
                  url: "WebService.asmx/GetNames",
                  data: request.term ,
                  dataType: "json",
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
  
                  error: function (XMLHttpRequest, textStatus, errorThrown) {
                      alert(textStatus);
                  }
              });
          },
          minLength: 2
           });
          });
        }) 
      &lt;/script&gt;
  </code></pre>