How do I display an error message for the 401 Unauthorized error?
My jquery:
$('.ero').click(function(e) {
e.stopPropagation();
e.preventDefault();
$.ajax({
type: 'POST',
url: '/stem_op/3',
success:function(msg){
$('.warning').fadeIn(500).css({
display: 'block',
position: 'absolute',
left: position.left + 50,
top: position.top - 25
}).append(msg).addClass("active")}
});
});
You could use the statusCode
map, from the docs -
A map of numeric HTTP codes and functions to be called when the response has the corresponding code. For example, the following will alert when the response status is a 404:
$.ajax({
statusCode: {
401: function() {
alert('401 fired');
}
}
});
If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error, they take the same parameters as the error callback.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.