I'd like to send an error to the user via ajax, if he don't fill the form properly.
This is how I send the answer to the browser via ajax:
if($bo){
header('HTTP/1.1 400 Bad Request');
header('Content-Type: application/json; charset=UTF-8');
$error['message'] = 'Some error message';
echo json_encode($error);
die;
}
And this is my jquery script:
$.ajax(
{
url: formURL,
type: "POST",
data: postData,
success: function(data, textStatus, jqXHR)
{
// some code ...
},
error: function(data, jqXHR, textStatus, errorThrown)
{
// how to get message here json{"message":"some_message"}
var jsonObj = JSON.parse(data);
$r = jsonObj.message;
alert($r);
}
});
I can see the message using firebug console but I don't know how to get the variable containing my error :/
Any suggestion please?
Thanks