I have this ajax function:
$(document).ready(function(){
setInterval(function() {
$.ajax({
url: 'php.php',
type: 'POST',
success: function(data){
if( data != "0" ) {
alert(data.a);
}
},
});
}, 5000);
});
and a PHP to return:
<?php
header('Content-type: application/json');
...some function
if($num>0){
echo json_encode(array("a" => "valueA", "b" => "valueB"));
}
else{
echo json_encode(0);
}
?>
when I have the alert message, it shows me "UNDEFINED" instead of "valueA". Is something wrong with my array or ajax?