Jquery Ajax not receiving php response correctly
- by Theo
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???