title: jquery ui autocomplete values not being displayed in textbox
body: <p>am working on a JQuery UI Autocomplete widget that connects to a Google Search Appliance I have tested the widget using both Fiddler and Visual Studio 2010 inbuilt testing tools and can verify that result are being returned from the queries that I am entering.</p>
  
  <p>My problems is that even though results are being returned they do not show in the textbox, currently I am using a combination of JQuery and an ashx web handler to retrieve and display the result, below is the code for the JQuery and the handler:</p>
  
  <p><strong>JQuery</strong></p>
  
  <pre><code>&lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8" /&gt;
  &lt;title&gt;GSA Autocomplete Widget&lt;/title&gt;
  &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /&gt;
  &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt;
  &lt;script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" href="/content/styles.css" /&gt;
  &lt;style&gt;
     .ui-autocomplete-loading {
     background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat;
  }
  &lt;/style&gt;
  &lt;script type="text/javascript"&gt;
      $(function () {
          var cache = {};
          $("#programmes").autocomplete({
              minLength: 2,
              source: function (request, response) {
                  var term = request.term;
                  if (term in cache) {
                      response(cache[term]);
                      return;
                  }
                  $.getJSON("handlers/Suggest.ashx", request, function (data, status, xhr) {
                     cache[term] = data;
                     response(data);
                  });
             }
         });
     });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="ui-widget"&gt;
  &lt;label for="programmes"&gt;Programmes: &lt;/label&gt;
  &lt;input id="programmes" /&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>ASHX Handler</strong></p>
  
  <pre><code>public class Suggest : IHttpHandler
  {
      public bool IsReusable
      {
          get { return true; }
      }
  
      public void ProcessRequest(HttpContext context)
      {
          if (string.IsNullOrEmpty(context.Request.QueryString[_QUERY_PARAM]))
              throw new Exception(string.Format("Could not find parameter '{0}'", _QUERY_PARAM));
  
          // Get the suggestion word from the parameter
          string term = context.Request.QueryString[_QUERY_PARAM];
          // Create an URL to the GSA
          string suggestionUrl = SuggestionUrl(term);
          // Call the GSA and get the GSA result as a string
          string page = GetPageAsString(suggestionUrl);
          // Convert the GSA result to Json
          string data = ConvertToJson(page);
          // Return the JSON
          context.Response.Write(data);
          context.Response.End();
      }
  
      private string SuggestionUrl(string term)
      {
          // You should modify this line to connect to your
          // own GSA, using the correct collection and frontend
          return "http://google4r.mc.man.ac.uk/suggest?max=10&amp;site=mbs_collection&amp;client=mbs_frontend&amp;access=p&amp;format=rich&amp;q=" + term;
      }
  
      private string GetPageAsString(string address)
      {
          // Add your own error handling here
          HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
          using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
          {
              StreamReader reader = new StreamReader(response.GetResponseStream());
              return reader.ReadToEnd();
          }
      }
  
      private string ConvertToJson(string gsaSuggestResult)
      {
          bool isFirst = true;
          StringBuilder sb = new StringBuilder();
          sb.Append("{ query:");
          foreach (string token in ParseGsaInput(gsaSuggestResult))
          {
              if (isFirst)
              {
                  sb.AppendFormat("'{0}', suggestions:[", token.Trim());
                  isFirst = false;
              }
              else
              {
                  sb.AppendFormat("'{0}',", token.Trim());
              }
          }
          sb.Remove(sb.Length - 1, 1);
          sb.Append(@"]}");
          return sb.ToString();
      }
  
      private IEnumerable&lt;string&gt; ParseGsaInput(string gsaSuggestResult)
      {
          gsaSuggestResult = gsaSuggestResult.Replace("[", "").Replace("]", "").Replace("\"", "");
          return gsaSuggestResult.Split(',');
      }
  
      private const string _QUERY_PARAM = "term";
  }
  </code></pre>
  
  <p>Currently the JSON result returns name and type.</p>
  
  <p>how do I go about binding the results from the web handler to the textbox?</p>