Wednesday, December 2, 2009

[jQuery] [autocomplete] Parse JSON ajax request

Hi all,

here is the code i use to parse an ajax request call as JSON string as
it is done for local data.

I think this should be the default behavior, but autocomplete uses a
"|" separated String...

parse: function(data){
var objArray = eval("(" + data + ")");
var parsed = [];
for (var i=0; i < objArray.length; i++) {
rawValue = objArray[i];
var value = this.formatMatch(rawValue, i+1, objArray.length);

parsed[parsed.length] = {
data: rawValue,
value: value,
result: this.formatResult && this.formatResult(rawValue) ||
value
}

}
return parsed;

}
Hope this helps.

No comments: