0
How do I get the PHP query values in AJAX?
AJAX
$.ajax({
type: 'post',
dataType: 'json',
url: 'listaGabaritosSelecionados.php',
success: function(url){
$('.retorno').html(url);
}
});
PHP
$mysqli = new mysqli("localhost", "root", "", "site");
$idProduto = 42;
$query = "SELECT * FROM produto where produto_id = '$idProduto'";
$consulta = $mysqli->query($query);
while($row = $consulta->fetch_assoc()){
$item = $row['item'];
$ids = explode(',', $item);
foreach ($ids as $valores) {
$selecionaGabaritos = "SELECT * FROM gabaritos where id = '$valores' ";
$banco = $mysqli->query($selecionaGabaritos);
while ($resultado = $banco->fetch_assoc()) {
$url[] = utf8_encode($resultado['url']);
}
}
}
json_encode($url);
Because I want to be sent a product ID to PHP, it makes a query in the database in 2 tables, if I run only the PHP file it runs, the problem is in AJAX for return!
RETURN PHP.FILE
<pre>array(2) {
[0]=>
string(14) "urlDoArquivoAI"
[1]=>
string(23) "http://www.teste.com.br"
}
</pre>
In AJAX is BLANK does not return me anything!
Try to give a:
echo json_encode($url);
in your AJAX file.– João Pedro Schmitz
Getting like this? $. ajax({ type: 'post', date: {id = Prod}, dataType: 'json', url: 'listingGabattribs.php', Success: Function(url){ //$('. return'). html(url); //console.log(url); echo json_encode($url); } });
– Cristiano Facirolli
No, this would be inside the AJAX file you call, in case no
listaGabaritosSelecionados.php
.– João Pedro Schmitz
Oh yes, thank you. But he continues to return nothing!
– Cristiano Facirolli