success and error in ajax code example

Example 1: ajax error

$.ajax({
    type: "post", url: "/SomeController/SomeAction",
    success: function (data, text) {
        //...
    },
    error: function (request, status, error) {
        alert(request.responseText);
    }
});

Example 2: how to show a success message when ajax called successfully

BY LOVE,
 1- "beforeSend" event used to execute something before ajax call
 2- "complete"   event used to execute something after the ajax called successfull.
 
$.ajax({
                url: ' @Url.Action("AttendanceUpdateLate", "Attendance")',
                data: { Emp: $("#txtEmpid").val(), Status: $("#ddlAttendance").val(), day: $("#ddlday").val(), Month: $("#Month").val() },
                datatype: "json",
                type: "POST",
                contenttype: 'application/json; charset=utf-8',
                async: true,
                success: function (data) {
                    alert(data);
                },
                beforeSend: function () {
                    alert("Alert showing before AJAX call");

                },
                complete: function () {
                  alert("Alert showing after AJAX call successfully");
                    $("#txtEmpid").val('');
                    $("#ddlday").val('');
                    $("#ddlAttendance").val('');
                },
                error: function (xhr) {
                    alert('error occured');
                }
            });

Example 3: jquery ajax on fail

fail: function(xhr, textStatus, errorThrown){
	alert('request failed');
}