jQuery Ajax error handling, show custom exception messages

前端 未结 21 3288
滥情空心
滥情空心 2020-11-22 01:50

Is there some way I can show custom exception messages as an alert in my jQuery AJAX error message?

For example, if I want to throw an exception on the server side v

21条回答
  •  半阙折子戏
    2020-11-22 02:22

    Although it has been many years since this question is asked, I still don't find xhr.responseText as the answer I was looking for. It returned me string in the following format:

    "{"error":true,"message":"The user name or password is incorrect"}"
    

    which I definitely don't want to show to the users. What I was looking for is something like below:

    alert(xhr.responseJSON.message);
    

    xhr.responseJSON.message gives me the exact message from the Json Object which can be shown to the users.

提交回复
热议问题