Skip to content

Instantly share code, notes, and snippets.

@bcalloway
Created January 3, 2012 20:58
Show Gist options
  • Save bcalloway/1556898 to your computer and use it in GitHub Desktop.
Save bcalloway/1556898 to your computer and use it in GitHub Desktop.
jQuery ajax callback with loader
// setup a loading dialog
function showLoader() {
$('body').append('<div id="dialog-loading"></div>');
$("#dialog-loading").dialog({
height: 35,
draggable: false,
resizable: false,
modal: true
});
$('span#ui-dialog-title-dialog-loading').after('<img src="' + basePath + 'images/ajax-loader-bar.gif" id="loader" />');
$('#dialog-loading').parent('.ui-widget-content').css("background", "none");
$('#dialog-loading').parent('.ui-widget-content').css("border", "none");
}
// remove loading dialog after success
function removeLoader() {
$('#dialog-loading').dialog("close");
$('#dialog-loading').remove();
}
$(document).ready(function () {
$('button#update').change(function () {
showLoader();
var id = $('input').val();
$.ajax({
url: 'path/to/action/' + id,
type: "POST",
traditional: true,
data: { 'id': id },
success: function (html) {
removeLoader();
$('div').html($(html));
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment