jquery autocomplete plugin - fetch works - fetchAll doesn't

jary

New Member
If I have something like this from the server side, from a fetch:\[code\]array(1) { [0]=> array(1) { ["nome"]=> string(7) "aaaa.br" } } [{"nome":"aaaa.br"}]\[/code\]The json of the above is:\[code\][{"nome":"aaaa.br"}]\[/code\]This Works:\[code\]parse: function(data) { return $.map(eval('('+data+')'), function(result) { return { data: result, value: result.nome, result: result.nome } });}\[/code\]The result is parsed successfully. If, instead of fetch, I change to fetchAll, the dump gets like this (here only the first index as example):\[code\]array(65) { [0]=> array(1) { ["nome"]=> object(stdClass)#7 (1) { ["nomeDominio"]=> string(7) "aaaa.br" } }\[/code\]The json conversion of the above:\[code\]string(2632) "[{"nome":{"nomeDominio":"aaaa.br"}}\[/code\]Here, the result is not successfully parsed. So I believe something needs to be changed on the js side. But I'm absolutely clueless. UPDATE: The nomeDominio is from the fetchObj PDO method, and corresponds to the column name on the database. It's a natural behaviour for fetch with PDO when FETCH::OBJ option is used.The php part of this js is:\[code\]$keyword = addslashes($_GET["q"]);$comandos = new ComandoController();$arr = $comandos->recebeNomeDominios($keyword);if(is_array($arr)){ echo json_encode($arr);}public function recebeNomeDominios($keyword){ $DominioDao = new DominioDao(); $objecto = $DominioDao->recebeNomeDominios($keyword); return $this->jsonArray($objecto);}private function jsonArray($objecto){ $json = array(); if(isset($objecto) && !empty($objecto)) { foreach($objecto as $obj) { $json[] = array('nome' => $obj); } } return $json;}\[/code\]Finally:\[code\]public function recebeNomeDominios($keyword){ try { $stmt = $this->_dbh->prepare("SELECT d.nomeDominio FROM dominio d WHERE d.nomeDominio LIKE '%".$keyword."%'");$stmt->execute();$resultado = $stmt->fetch(PDO::FETCH_OBJ);return $resultado;}catch (PDOException $ex){ echo "Erro: " . $ex->getMessage();}}\[/code\]Any advice?MEM
 
Back
Top