jquery ui - jQueryUI autocomplete response data -


scenario

i have jqueryui autocomplete in page. data retrieved through ajax call. working fine.

question

as jqueryui api, source property setter.

is there autocomplete property exposing retrieved data?

in other term, if re-focus autocomplete bound input , still contains previous searched terms, can show autocomplete results without re-excuting ajax call?

i have searched similar questions. sirderpington, succeed in re-opening result menu. still, ajax call re-processed.

        $('myselector').autocomplete().on("focus", function () {             $(this).autocomplete("search");         }) 

so question remains.

if understood right want show same results if user re-focusses input?

in jsfiddle seems work i'm not sure if trigger ajax call. anyway see did:

$('#autocomplete').autocomplete({     source: availabletags,     minlength: 0 }).focus(function () {     var $this = $(this);     var inputval = $this.val();     //just check prevent showing results if inputval empty     if (inputval !== '') {         $this.autocomplete("search");     } }); 

notice docs search method:

when invoked no parameters, current input's value used.

edit

using sort of "cache" seems way solve issue. because can not use source used jsfiddle's /echo/json/ , set cache whole source (availabletags). imagine have real request , save response. work fine when using real source. (the alert doesn't popup when results cached , input doesn't change)

updated fiddle

updated code

var cache = {}; $('#autocomplete').autocomplete({     source: function (request, response) {         var term = request.term;         //check if searched input in cache , return response         if (term in cache) {             response(cache[term]);             return;         }          $.getjson("/echo/json/", request, function (data, status, xhr) {             alert("request triggered!");             //write response in cache             cache[term] = availabletags;             response(availabletags);         });     },     minlength: 0 }).focus(function () {     var $this = $(this);     var inputval = $this.val();     if (inputval !== '') {         $this.autocomplete("search");     } }); 

also mentioned in comments here again: documentation entry


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -