If you are using $.ajax()
you can use somthing like this:
$.ajax({
url: "destination url",
success: sdialog,
error: edialog,
// shows the loader element before sending.
beforeSend: function() {
$("#imgSpinner1").show();
},
// hides the loader after completion of request, whether successfull or failor.
complete: function() {
$("#imgSpinner1").hide();
},
type: 'POST',
dataType: 'json'
});
Although the setting is named "beforeSend", as of jQuery 1.5 "beforeSend" will be called regardless of the request type. i.e. The .show()
function will be called if type: 'GET'
.