Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The "JSON response", as you've described it, is not valid JSON. If that is what your service is returning, it's wrong. That text represents 3 distinct Javascript objects. Any of the three lines, taken alone, is valid JSON. With those lines concatenated all together, it is not valid JSON. </p> <p>This is valid JSON representing an array of three objects:</p> <pre><code>[{"First":"Steve","Second":"AK"}, {"First":"Evet","Second":"EV"}, {"First":"Stevens","Second":"SV"} ] </code></pre> <p>(whitespace doesn't matter)</p> <p>This is not valid JSON :</p> <pre><code>{"First":"Steve","Second":"AK"} {"First":"Evet","Second":"EV"} {"First":"Stevens","Second":"SV"} </code></pre> <p>So if that is an accurate picture of the response, your service is broken. Fix that first, then we can answer the question.</p> <hr> <p>After you get a response in the proper form, eg, </p> <pre><code>[{"First":"Steve","Second":"AK"}, {"First":"Evet","Second":"EV"}, {"First":"Stevens","Second":"SV"} ] </code></pre> <p>...then you can display the results. But you want to display only the first element of each item in the array. To do that you need to map that original array to a different array, an array of strings rather than an array of objects. You can use the jQuery <code>map()</code> function to do that. It looks like this: </p> <pre><code> $.map( realArray, function(val, i) { ...map one item here... }); </code></pre> <p>In your success function, with your returned data, you'd use it like this: </p> <pre><code> success: function (data){ response($.map(data, function(item) { return item.First; })); }, </code></pre> <p>The function that gets called by map, once for each item in the original arrap, transforms an item like <code>{"First":"Steve","Second":"AK}</code> into an item like <code>"Steve"</code>. For the entire array like</p> <pre><code>[{"First":"Steve","Second":"AK"}, {"First":"Evet","Second":"EV"}, {"First":"Stevens","Second":"SV"} ] </code></pre> <p>..the output of the call to <code>$.map()</code> is <code>["Steve", "Evet", "Stevens"]</code>. This result gets passed to the response function, which then displays that list of items in the autocomplete widget.</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.
 

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