Jquery Ajax not receiving php response correctly
Posted
by
Theo
on Stack Overflow
See other posts from Stack Overflow
or by Theo
Published on 2012-12-14T17:00:16Z
Indexed on
2012/12/14
17:03 UTC
Read the original article
Hit count: 224
I'm sending a JSON response from php to jquery:
foreach ( $obj as $o )
{
$a[ $o->key] = utf8_encode($o->id);
}
die(json_encode($a));
my html/jquery code is:
$.ajax({
type:'POST',
url: "imoveis/carrega_bairros",
data: ({cidade:10}),
dataType:"json",
success: function(ret)
{ alert(ret)
if(ret.success)
{
// ...
}
else
alert("error");
}
});
The json response is perfect (i get it on the console), but jquery is receiving a NULL ret object and it alerts "error". What's the problem???
© Stack Overflow or respective owner