What is the purpose of the ajax error function?

2

I have some doubts, what is the error of ajax?

$.ajax({
            url: 'ws/controller/sys_controller.php?id=4',
            type: 'post',
            data: dados,
            success: function (data) {
                /*$("#loading").hide();
                $('#message').html('');
                $("#message").append(data);
                $("#message").show( "puff", { times:3, distance:100, direction:'down' }, 2000 ).delay(5000).hide( "puff", { times:3, distance:100, direction:'down' }, 5000 );*/
                null;
            },
            error: function (request, status, error) {
                alert(request.responseText);
            }
        });      
    
asked by anonymous 23.12.2017 / 11:08

1 answer

3

Serves so that if the backend request fails, you have an error-handling scope allowing you to provide feedback to the client interface.

The function gets three arguments:

  

Request that is the jqXHR object itself, allowing you to make a new request   ajax or use the internal methods of that object.

     

Status may receive the following values in addition to null, may return   with "timeout", "error" , abort , and parsererror      

Error that refers to the error message regarding httpd status that   occurred on the server, such as "Not Found" or "Internal Error   server "

With this you can establish an error handling algorithm ( exceptions ) that provides more detailed information about the problem to the user or administrator.

You can consult and gain a more detailed knowledge of the documentation on this page: Jquery Ajax

    
23.12.2017 / 11:25