I feel as if I'm making a noob mistake here, but it's annoying the hell out of me so I guess I'll post!
I'm trying to get message in the php array to be logged to the console. What actually happens is, data returns nothing, message returns 'success' and data.message is undefined.
JavaScript:
var message = '';
jQuery.ajax({
url: '/dir/myfile.php',
type: "POST",
dataType: "json",
data: { message : message },
error: function(xhr, text, thrown){
console.log('error');
},
success: function(data, message, text, xhr){
if(data.message){
console.log('data exists');
} else if(message){
console.log(message);
}else{
console.log('no data');
}
},
})
PHP:
$output = array(
'code' => 1,
'message' => 'Please work!'
);
echo json_encode($output);
*yourdomainhere*/dir/myfile.php, do you see the JSON output you're expecting it to hand back to the AJAX request?jQuery.postto post your dataheader('Content-type: application/json')