Seems to be everything ok, but I can't access the data inside the javascript. I know its something easy and have a lot of tutos everywhere, but I'm a little confused. Someone can help me?
Here is the three pieces of code, really simple:
foo.js
$.ajax({ data: {'termo': termo}, url: 'http://localhost/tarefa66/sysvendas/getFestas.php', success: function(data) { $('#resultado').text(JSON.parse(data)[0]); } });
getFestas.php
echo json_encode(getFestas($_GET['termo']));
dao.php
$getFestas = $pdo->query("SELECT * FROM festa f WHERE f.nome LIKE '%" . $termo . "%'"); return $getFestas->fetchAll(PDO::FETCH_OBJ);
Output on network tab (Firefox) http://i.stack.imgur.com/JfKuS.png
============================================================
Problem solved. 1. The complete method don't receive 'data', 'success' do.
The php return is something like '[{"prop": 'value'}]', so doing this 'JSON.parse(data)[0]' I was just accessing the Object inside the array - that can't be printed.
So the right use is: obj = JSON.parse(data)[0];
and after access like obj['prop']
.