Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>According to the <a href="http://jqueryui.com/demos/autocomplete/" rel="noreferrer">documentation</a>, when using a URL as the source, the response will need to be a JavaScript array:</p> <blockquote> <p>When a String is used, the Autocomplete plugin expects that string to point to a URL resource that will return JSON data. It can be on the same host or on a different one (must provide JSONP). The request parameter "term" gets added to that URL. The data itself can be in the same format as the local data described above.</p> </blockquote> <p>So, your URL is going to have to be something that returns a JavaScript array, <strong>not</strong> a simple HTML page like you're using. Here's a working example using a ASP.NET handler (I call it <code>autocomplete.ashx</code>):</p> <pre><code>&lt;%@ WebHandler Language="C#" Class="autocomplete" %&gt; using System; using System.Web; using System.Web.Script.Serialization; using System.Linq; public class autocomplete : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/javascript"; //load your items from somewhere... string[] items = { "ActionScript", "AppleScript", "Ruby", "Scala", "Scheme" }; //jQuery will pass in what you've typed in the search box in the "term" query string string term = context.Request.QueryString["term"]; if (!String.IsNullOrEmpty(term)) { //find any matches var result = items.Where(i =&gt; i.StartsWith(term, StringComparison.CurrentCultureIgnoreCase)).ToArray(); //convert the string array to Javascript context.Response.Write(new JavaScriptSerializer().Serialize(result)); } } public bool IsReusable { get { return false; } } } </code></pre> <p>HTML and JavaScript:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Auto complete demo&lt;/title&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"&gt;&lt;/script&gt; &lt;link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { $("#tags").autocomplete({ source: '/autocomplete.ashx' }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="text" id="tags" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload