parsing json in jquery autocomplete -


i've used simon whatley's code autocomplete plugin. now, need in parsing json data. here code:

    $("#country").autocomplete("data/country.cfm",{         minchars:1,         delay:0,         autofill:false,         matchsubset:false,         matchcontains:1,         cachelength:10,         selectonly:1,         datatype: 'json',         extraparams: {                 format: 'json'         },         parse: function(data) {             var parsed = [];             (var = 0; < data.length; i++) {                  parsed[parsed.length] = {                 data: data[i],                 value: data[i].name,                 result: data[i].name                  };             }              return parsed;         },         formatitem: function(item) {             return item.name;         }    }); 

for example, json string:

[{"name":"country1"},{"name":"country2"},{"name":"country3"}] 

what results, of course, values country1, country2, country3. however, right in textbox when type (e.g. type "cou") "undefined". if click that, shows in textfield whole string [{"name":"country1"},{"name":"country2"},{"name":"country3"}].

i've tried these still not working: jquery autocomplete, how parse json request url info? jquery autocomplete json response

help please. thanks!

you can use

var countries = json.parse(data); 

since you're using jquery though, it's bit safer use jquery.parsejson() in case browser doesn't have native parser:

var countries = jquery.parsejson(data); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -