What is the ajax error function for?

Asked

Viewed 8,559 times

3

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

$.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);
            }
        });      

1 answer

5


It serves so that if there is a request failure with the backend you have a scope of error handling allowing to provide feedback to the client interface.

The function takes three arguments:

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

Status can receive the following values besides null, can return with "timeout", "error", "abort", and "parsererror"

Error referring to error message referring to httpd status that occurred on the server, as "Undetected" or "Internal error of server"

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.