jquery - cannot fill autocomplete with data -


var first = true; var json = '['; if (!first) {     json += ','; } else {     first = false; } // $.each(data, function(i, elem) { json += '{label:"kasun"}';   json += ']'; console.log(json); $("#p_name").autocomplete({     minlength: 2,     source: x,     focus: function (event, ui) {         $("#p_name").val(ui.item.label);         return false;     },     select: function (event, ui) {         return false;     } }) 

i tried above code populate auto complete data.when try following error. if u have alternative please let me know

    http://localhost/new/patient_channel/[%7blabel:%22kasun%22%7d]?term=ka 404 (not found)  

the source should array, not string

you need

var json = [];  // $.each(data, function(i, elem) { json.push({label:"kasun", value:"kasun"}) //or json.push('kasun')  //});  console.log(json);  jquery(function ($) {     $("#p_name").autocomplete({         minlength: 2,         source: json,         focus: function (event, ui) {             $("#p_name").val(ui.item.label);             return false;         },         select: function (event, ui) {             return false;         }     }) }); 

demo: fiddle or fiddle


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -