javascript - Autocomplete function works just in open script tag and not in the same tag in ajax.done function -
here's code:
var components = new array(); $("#types").change(function() { $.ajax({ method: "get", url: "/index.php/field/get-fields-by-type/" + $("#types").val(), datatype: "json" }).done(function( data ) { (var = 0, len = data.length; < len; i++) { var dat = data[i]; components.push({ value: dat.name, data: dat.id }); } //here get: typeerror: $(...).autocomplete not function $('#productfield-field_id').autocomplete({ lookup: components, onselect: function (suggestion) { alert('you selected: ' + suggestion.value + ', ' + suggestion.data); $("#productfield-field_id").val(suggestion.data); } }); }); }); // here works charm , functionality should doing $('#productfield-field_id').autocomplete({ lookup: components, onselect: function (suggestion) { alert('you selected: ' + suggestion.value + ', ' + suggestion.data); $("#productfield-field_id").val(suggestion.data); } }); i want know reason. why im getting typeerror message autocomplete in $.ajax.done function when it's in script tag plain open works , functionality no errors. , how can solve problem add components lookup
i've debugged far , can tell components has value in proper style formatted , jquery selecting #productfield-field_id valid , can find it. tried example adding value , worked.
im using autocomplete: https://www.devbridge.com/sourcery/components/jquery-autocomplete/ , tried replace autocomplete "devbridgeautocomplete" , results same. works in open not in ajax.done function.
i've tried make alternative solution putting plain open code standalone javascript function takes array parameter , tried call autocomplete function in that. typeerror too.
also jquery , autocomplete included webpage.
browsers i've tried: firefox & chrome
Comments
Post a Comment