I'm making a jquery post call like so:
var t1 = $("#form").serialize();
$.ajax({
type: "POST",
url: "save_test.php",
data: t1,
cache: false,
success: function(data){
if (data.st) {
alert("Success");
}
else if (data.error) {
alert("Error");
}
}
});
My PHP Looks like this for my error test:
$res = new stdClass();
$res->error = 'ERROR SEEN';
echo json_encode($res);
exit();
Why can I not access my json encoded data returned from PHP? I would expect this to trigger my data.error alert.
use datatype:json
in jquery code
or you can use
var d=$.parseJSON(data)
then use d.st
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With