jQuery Ajax error handling, show custom exception messages

前端 未结 21 2721
滥情空心
滥情空心 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:36

    If someone is here as in 2016 for the answer, use .fail() for error handling as .error() is deprecated as of jQuery 3.0

    $.ajax( "example.php" )
      .done(function() {
        alert( "success" );
      })
      .fail(function(jqXHR, textStatus, errorThrown) {
        //handle error here
      })
    

    I hope it helps

提交回复
热议问题