javascript - Why isn't JQuery showing my autocomplete fields? -


context: i'm attempting setup jquery autocomplete using data gets sent in server. when user changes field, autofill data gets sent in backend such can select supplied value if desire. backend code functional, can see array of autocomplete data if console.log(data)it on frontend.

my issue that, though frontend code requesting , receiving autocomplete data, when used jquery's built in autocomplete options, never shows options on frontend.

here's code:

$.ajax({       type: "get",       url:"/autocomplete/"+event.target.id+"/"+$(this).val(),       success : function(data){         console.log(data);         $(event.target.id).autocomplete({           source: data         });       } }); 

where event.target.id id of input field i'd autocomplete. again, of works fine. when console.log(data), shows array of items want use autocomplete, when run

$(event.target.id).autocomplete({source:data}); 

it doesn't show autocomplete options on frontend.

any idea how can fix this? i've disabled adblocker , tried in bunch of different browsers , results never show standard dropdown-list autocomplete.

using tactics @jaromanda x suggested, found event.target.id field returning name of field intended autocomplete, didn't include "#" necessary denote id via jquery. functional code looks now:

$.ajax({       type: "get",       url:"/autocomplete/"+event.target.id+"/"+$(this).val(),       success : function(data){         console.log(data);         $("#"+event.target.id).autocomplete({           source: data         });       } }); 

yeah, feels little hacky, code runs is, in fact, code runs.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -