我正在尝试让 jgrowl 消息在单击时显示,以便我可以通知用户可能会很长的过程。 单击时,第一个 jgrowl 应该显示,然后进行 ajax 调用,成功后第一个 jgrowl 被删除,然后一个新的 jgrowl 显示过程完成。 在我添加 ajax 调用之前,它按预期工作,其中第一个 jgrowl 被第二个 jgrowl 删除。 请你看看我可能做错了什么?
$('.import').click(function(e) {
$.jGrowl('Please wait for processing to complete which can take a few minutes.', {
sticky: true,
position: 'center',
header: 'PROCESSING IMPORT',
theme: 'bg-primary'
});
return $.ajax({
type: "POST",
dataType: 'text',
async: false,
url: `/ids.aspx?ids=1`,
success: function(e) {
$(".jGrowl-notification:last-child").remove();
$.jGrowl('Process Complete.', {
life: 3000,
position: 'center',
header: 'PROCESSING COMPLETE',
theme: 'bg-primary'
});
},
});
});
这段代码运行良好。 我将尝试整理一下它,但它满足了我的需要。
$('.import').click(function (e) {
$.jGrowl('Please wait for processing to complete which can take a few minutes.', {
sticky: true,
position: 'center',
header: 'PROCESSING IMPORT',
theme: 'bg-primary',
open: function () {runImport(e)}
});
});
function runImport(e) {
var ids = '0';
$("#tableValuesModel tbody input:checkbox:checked").each(function () {
ids = ids + '-' + $(this).attr("id");
});
return $.ajax({
type: "POST", dataType: 'text', async: true, url: `/_content/data/ajax/valuesmodel/valuesmodelids.aspx?ids=${ids}`,
success: function (e) {
$(".jGrowl-notification:last-child").remove();
$.jGrowl('Process Complete.', {
life: 3000,
position: 'center',
header: 'PROCESSING COMPLETE',
theme: 'bg-primary'
});
},
});
}