Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning a JSON Object from a Java Servlet Requested by the Source of a jQuery UI Autocomplete Widget
    primarykey
    data
    text
    <p>Though the title might be either too specific or too vague, I have a question in regards to what the Autocomplete widget sends to my servlet when it attempts to retrieve a JSON object. The source option of the Autocomplete allows me to specify a URL to, in this case, my servlet where it expects a JSON object to be returned. Unfortunately, the jQuery UI Autocomplete documentation has me a bit confused:</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.</p> </blockquote> <p>Now, does this mean that if my servlet URL were something like: "<code>MyServlet</code>," would the new URL be "<code>MyServlet?term</code>"? I send multiple AJAX requests to this servlet, and I normally decipher what procedure I should take with each based on a parameter "command" that I post with each AJAX request. So, when the Autocomplete makes its request to my servlet, what exactly do I check to see if it's asking for this particular JSON? For every other request, I do something like this:</p> <pre><code>if(request.getParameter("command").equals("getUsers") { // Code to handle Getting Users... } else if(request.getParameter("command").equals("getEvents") { // Code to handle Getting Events... } else if(request.getParameter("command").equals("getBugs") { // Code to handle Getting Bugs... } </code></pre> <p>How can I check to see if the request is coming from the Autocomplete? Could I tag on this "command" parameter to the URL that I pass into the source, kind of like "<code>MyServlet?command=autocomplete</code>" to let it know, or would this even be necessary?</p> <p><em><strong>EDIT</strong>:</em> So after rereading the documentation, it actually sounds as though using a string referencing a URL as the source will basically make a request to that source each time it makes a search, and that "term" parameter simply carries what was in the search box when it began. In other words, does this mean that it doesn't simply load a JSON of <em>all possible</em> terms and just uses it like an array? Rather, it goes to fetch the possibilities at each search?</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.
 

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