Here we are going to explain what is ajaxError() method  or how to use ajaxError()  method or why use ajaxError() method  or   how to show message on the web page when error occurred while performing ajax request  in jQuery with example.


The jQuery ajaxError() method is used to track error when ajax request completes with an error.

Whenever an Ajax request completes with an error, jQuery triggers the ajaxError event. Any and all handlers that have been registered with the .ajaxError() method are executed at this time.

Let’s see a demonstration example of ajaxError() method 

<script src="/Scripts/jquery-3.2.1.js"></script>
 <script type="text/javascript">
       $(document).ready(function () {
            varserviceURL = '/Home/Get';             $.ajax({
                type: "Get",
                url: serviceURL,
                data: param = "",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: successFunc              
            function successFunc(data, status) {    
               $(document).ajaxError(function(event, xhr, option, ex) {
            $("#divAjaxError").text("Error occurred while                 sending ajax request " + xhr.responseText);
<div id="divAjaxError">


In the above example code, when ajax request completes with error “Error occurred while performing  ajax request” is written inside “divAjaxError”. After this error message, it also writes the response text returned from the server.  This event can be used to show default message in case of error.

I hope it will help to you.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like