Arun Kumar ha scritto:
Where can I convert to a JSON object using eval and use it as a local
JSON data?
I've solved this way:
In the server side I create a string separated by "\n" chars that
contains N json objects :
foreach($list as $c) {
$record = array();
$record['id'] = $c->fields['id'];
$record['comune'] = ucwords(strtolower($c->fields['comune']));
$record['regione'] = ucwords(strtolower($c->fields['regione']));
$record['cap'] = $c->fields['cap'];
$record['provincia'] = $c->fields['provincia'];
$return[] = $record;
}
foreach($return as $row) {
echo json_encode($row);
echo "\n";
}
and in the javascript side:
$("#localita").autocomplete('ajax.php', {
formatItem: function(row) {
item = eval("(" + row + ")");
return item.comune+' - '+item.cap+' - '+item.provincia+' -
'+item.regione;
}
}
Hope this helps :-)
--
gianiaz.net - web solutions
p.le bertacchi 66, 23100 sondrio (so) - italy
+39 347 7196482