Hola Amiguito,
es muy facil con Jquery.
mira este ejemplo, no hace falta que te explique nada:
Código PHP:
Ver original// Assign handlers immediately after making the request,
// and remember the jqXHR object for this request
var jqxhr = $.ajax( "example.php" )
.done(function() {
alert( "success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "complete" );
});
// Perform other work here ...
// Set another completion function for the request above
jqxhr.always(function() {
alert( "second complete" );
});
esta en la pagina oficial
https://api.jquery.com/jQuery.ajax/