How to display status description in AJAX?

I have a page that saves data using jQuery AJAX. On the server side, if the save process failed, I want to set the StatusDescription of the Response object: "Hey, this is Patrick!". The problem is that I cannot display StatusDescription on the client side! It always gives me "Internal Server Error". How can I display my own error message?

Save.ashx

Catch ex As Exception Transaction.Rollback() context.Response.StatusCode = 500 context.Response.StatusDescription = "Hey this is Patrick!" End Try 

AJAKS

 $.ajax ({ type: 'POST', url: 'Save.ashx', data: data, async: false, success: function(Data, TextStatus, XHR) { alert(Data); }, error: function(XHR, TextStatus, ErrorThrown) { alert(ErrorThrown); } }); 
+4
source share
2 answers

use XHR.responseText and then see what the error is.
Here is a good link regarding jQuery Call error
JQuery Ajax error handling, display custom exception messages

 $.ajax ({ type: 'POST', url: 'Save.ashx', data: data, async: false, success: function(Data, TextStatus, XHR) { alert(Data); }, error: function(XHR, TextStatus, ErrorThrown) { alert(XHR.responseText); } }); 
+1
source

Instead, I would return a string message in the form of a response to the server, and then you can use it in your error function.

0
source

Source: https://habr.com/ru/post/1444734/


All Articles