I want to show the download dialog when an AJAX request is executed; and I want to use this piece of code anywhere in my project.
$("div.add_post a").click(function(){
var dlg = loadingDialog({modal : true, minHeight : 80, show : true});
$.ajax(
{
url : "/add.php",
beforeSend : function (){
dlg.dialog("show");
},
complete : function (){
dlg.dialog("hide");
}
}
);
return false;
})
function loadingDialog(dOpts, text = " , ...")
{
var dlg = $("<div><img src='/theme/style/imgs/busy.gif' alt=''/> "+text+"<div>").dialog(dOpts);
$(".ui-dialog-titlebar").hide();
return dialog;
}
NEW CODE
$("div.add_post a").click(function(){
var dlg = loadingDialog();
$.ajax(
{
url : "/add.php",
complete : function (){
dlg.dialog("hide");
},
success : function (data) {
$(data).find("#add_post").dialog();
}
}
);
return false;
})
function loadingDialog(dOpts = {modal : true, minHeight : 80, show : true}, text = " , ...")
{
var dlg = $("<div><img src='/theme/style/imgs/busy.gif' alt=''/> "+text+"<div>").dialog(dOpts);
$(".ui-dialog-titlebar").hide();
return dlg;
}
return - Error: there is no such "hide" method for the widget instance of the dialog
LAST NEW CODE
$("div.add_post a").click(function(){
var dlg;
loadingDialog();
$.ajax(
{
url : "/add.php",
complete : function (){
dlg.dialog("hide");
},
success : function (data) {
var form = $(data).find("#add_post");
form.dialog({title : " ", modal : true});
}
}
);
return false;
})
function loadingDialog(dOpts = {modal : true, minHeight : 80, show : true}, text = " , ...")
{
dlg = $("<div><img src='/theme/style/imgs/busy.gif' alt=''/> "+text+"<div>").dialog(dOpts);
$(".ui-dialog-titlebar").hide();
}
TO RETURN:
TypeError: dlg undefined
dlg.dialog ("hide");
source
share