我想使用 noty 插件在 ajax 调用期间显示消息。为此,我必须打开两个通知框,一个在 beforeSend 中,一个在成功回调中。
$('#insert').on('click', function() {
$.ajax({
type: "POST",
url: action.php,
beforeSend: function() {
callNoty('Waiting...');
},
success: function(data) {
callNoty('Insert ok');
}
});
});
JS
$(function() {
callNoty(text) {
var n = noty({
layout: 'center',
theme: 'relax',
type: 'success',
text: text,
dismissQueue: true, // If you want to use queue feature set this true
template: '<div class="noty_message"><span class="noty_text"></span><div class="noty_close"></div></div>',
animation: {
open: { height: 'toggle' }, // or Animate.css class names like: 'animated bounceInLeft'
close: { height: 'toggle' }, // or Animate.css class names like: 'animated bounceOutLeft'
//easing: 'swing',
speed: 0 // opening & closing animation speed
},
timeout: 3000, // delay for closing event. Set false for sticky notifications
force: false, // adds notification to the beginning of queue when set to true
modal: true,
maxVisible: 2, // you can set max visible notification for dismissQueue true option,
killer: true, // for close all notifications before show
closeWith: ['click', 'hover'], // ['click', 'button', 'hover', 'backdrop'] // backdrop click will close all notifications
callback: {
onShow: function() {},
afterShow: function() {},
onClose: function() {},
afterClose: function() {},
onCloseClick: function() {},
},
buttons: false // an array of buttons
});
};
});
我读到您可以即时编辑文本和类型,我会这样做,因此在 beforeSend 上打开一个通知框并在成功回调中更改类型和文本。我怎么能那样做?谢谢