ruby on rails - Help with JQuery Autocomplete -


i have json in following format.

[{"tag":{"name":"& awards","id":142}},{"tag":{"name":"& bisexual bars","id":207}},{"tag":{"name":"& clubs","id":40}},{"tag":{"name":"& imaging","id":1188}}} 

and using following code

$("#tags_name").autocomplete({   source: "/companies/autocomplete_tags2.json",   width: 320,   datatype: 'json',   highlight: false,   scroll: true,   scrollheight: 300,   parse: function(data) {     var array = new array();     for(var i=0; < data.tag.length; i++){       array[i] = {data: data.tag[i], value: data.tag[i].value, result: data.tag[i].id };     }     return array;   } }); 

when load page error "newuncaught syntaxerror: unexpected end of input"

what missing here?

your parse function wrong json have. have array of objects in json.

it should like

  parse: function(data) {     var array = new array();     for(var i=0; < data.length; i++){       array[i] = {data: data[i].tag, value: data[i].tag.name, result: data[i].tag.id };     }     return array;   } 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -