I've tried to submit with $.post, on php script i do a query and it return an array, so i use json_encode($results), but... it seems return an string than the JS don't recognizes as an array.
The JS:
$.post('plugins/LiveResult_1.0/LiveResult_1.0.php',
{
tab:tabela,
val:ultimo,
campos:campos
},
function(resp){
for(i=0;i<resp.length;i++){
$('ul.ul_options',obj.parents('.div_liveresult')).append('<li>'+resp[i]+'</li>');
}
})
The PHP:
$tabela = $_POST['tab'];
$pesq = $_POST['val'];
include('../../classes/Conexao.class.php');
new ConectaBanco;
$res = array();
$sql = "SELECT * FROM `$tabela` WHERE ";
$campos = $_POST['campos'];
for($i = 0;$i<count($campos)-1;$i++){
$sql .= "`".$campos[$i]."` LIKE '%$pesq%' OR ";
}
$sql .= "`".$campos[count($campos)-1]."` LIKE '%$pesq%' GROUP BY `id`";
$query = mysql_query($sql) or die(mysql_error());
while($result = mysql_fetch_assoc($query)){
$res[] = $result;
}
echo $resp = json_encode($res);