Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I implemented something like that, however, my implementation makes use of <a href="http://docs.jquery.com/UI/Autocomplete" rel="nofollow noreferrer">jQuery UI Autocomplete</a>. </p> <p>I use a simple trick, whereby the data returned from the server is a set of strings separated by a newline character "\n", on each line there is a string with the format <strong>suggestion::url</strong>. On the client, I simply split at the separator (I use <strong>::</strong>) and extract the suggestion from the first offset of the resulting array, and the URL from the second. Example:</p> <pre><code> $("#search").autocomplete("/some/page", { selectFirst: false, formatItem: function(data, i, n, value) { //make the suggestion look nice return "&lt;font color='#3399CC'&gt;" + value.split("::")[0] + "&lt;/font&gt;"; }, formatResult: function(data,value) { //only show the suggestions and not the URLs in the list return value.split("::")[0]; } }).result(function(event, data, formatted) { //redirect to the URL in the string var pieces = formatted.split("::"); window.location.href = pieces[1]; }); </code></pre> <p>To clarify what I mean, suppose you type 'goo'. The server might return:</p> <pre><code>google::www.google.com\ngoodstuff::www.example.com </code></pre> <p>That user will see a list appear with 'google' and 'goodstuff'. Clicking on one of those will execute the <code>result</code> method of Autocomplete, where I simply take the URL part of the string and redirect. Hope that helps.</p>
    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. 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