As I referred to in another question needs to use the echo
.
To pass several variables you can make an array with them and use the echo
combined with json_encode().
// Variaveis
$nome = $Fetchi['nome'];
$email = $Fetchi['email'];
$tipo = $Fetchi['tipo'];
$senha = "Digite uma nova senha...";
$ativado = $Fetchi['ativado'];
$retorno = array($nome, $email, $tipo, $senha, $ativado);
echo json_encode($retorno);
On the client side (javascript) must use the JSON.parse() thus:
success: function(result){
var resultado = JSON.parse(result);
This way you will receive an array like this:
[nome, email, tipo, "Digite uma nova senha...", ativado]
To access the senha
can use for example alert(resultado[3]);
if you want to see all members of the array use: alert(resultado.join('\n'));
There is the possibility of passing an object as well, in some cases it is preferred. So in PHP you need to do so:
$retorno = array('nome'=>$nome, 'email'=>$email, 'tipo'=>$tipo, 'senha'=>$senha, 'ativao'=>$ativado);
echo json_encode($retorno);
In javascript you still use JSON.parse() but you will receive an object in this format:
{nome: 'valor do nome', email: 'valor do email', tipo: 'valor do tipo', senha: "Digite uma nova senha...", ativao: 'valor do ativao'}
Note: As @Jader suggested, use also dataType: json
in AJAX to facilitate the parse of the response.