0
I have the following answer in jSon
received from a file php
.
{"1":"OK","2":"n"}
I want it now, in jQuery
catch the values of indexes 1
and 2
which are respectively "OK"
and "n"
.
How to do this?
My block is like this:
$("a#bloqDesbloq").click(function() {
$.post ("../_requeridos/alteraAdministrador.php", {
idAdministrador : $(this).attr('idAdmin'),
bloq : $(this).attr('bloq')
}, function(retorno){
alert(retorno[1]);
if (retorno[1] == "OK") {
if (retorno[2] == "s") $("a#bloqDesbloq img").prop("src",'_img/desbloquear.png')
if (retorno[2] == "n") $("a#bloqDesbloq img").prop("src",'_img/bloquear.png')
location.reload();
} else {
alert("Erro no bloqueio");
location.reload();
}
}
);
return false;
});
Making:
alert(retorno[1]);
It only gives double quotes as return
"
Use the
JSON.parse()
or correctly define the parameterdataType
.– Woss
Ok return = JSON.parse(_return);
– Carlos Rocha