I saw you put in tags
jQuery, then you can use it, so you will not have problems, a simple use example is.
// PHP
$retorno = array();
$sql = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$sql->execute(array($_POST['id']));
$retorno['dados'] = $sql->fetchAll();
die(json_encode($retorno))
With this, your PHP will already return one json
for your ajax
that will stay that way...
function listarUsuarios(){
$.ajax({
type: 'POST',
url: 'SUA URL DO ARQUIVO PHP',
dataType: 'json',
data: {
id: 1
},
success: function(data){
console.log(data)
$('body').append('<h1>'data.nome'</h1>')
}
})
}
// Aqui você executa sua função
listarUsuarios()
And that way you solve your problem.
Please explain your solution better.
– RFL