for an incorrect Ajax action, I set with HTTP header code to 403 and send the following response :
{"code":"403","status":"Forbidden","message":"You cannot do this"}
However, I can't access this data when handling my error... Is it possible to acess "message"data from jqXHR ?
something like jqXHR.message ?
Many thanks for your help...
EDIt :
error: function (xhr) { $(".alert").html(xhr.responseText); },
This returns :
{"code":"403","status":"Forbidden","message":"You cannot do this"}
But xhr.responseText.message doesn't return anything ...
EDIT : this code works :
error: function (xhr) { var jsonResponse = JSON.parse(xhr.responseText); $(".alert").html(jsonResponse.message); },
When there is an AJAX error response or the AJAX request times out, you'll want to log as much information as you have, including the error message that jQuery gives you, the url and the request data. $. ajax(url, { "data": requestData, "type": "POST", "timeout": 5000 }) .
The 500 Internal Server Error is a very general HTTP status code. It means something has gone wrong on the website and webserver is unable to specify what exactly, thus failing in fulfilling the request made by the client.
You should be getting in jQuery 'error' callback... http://api.jquery.com/jQuery.ajax/
error: function(xhr, status, error) { alert(xhr.responseText); }
(btw.. ur code?)
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