I saw that you put in tags
jQuery, so you can use it, so you will not have problems, a simple example of use 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 a json
to its ajax
which will look like this ...
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.