I'd like to use noty plugin to display messages during ajax calls. To do this I had to open two noty notification box, one in beforeSend and one in success callback.
$('#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
});
};
});
I read that you can edit the text and type on the fly and I would do it so open a notification box on beforeSend and change type and text in success callback. How could I do that? Thank you
I guess I am five years late to this thing but you can do this the following way : You must have the noty.js files linked to the root html folder . Focus on the sucess and error handlers
So we just call the new Noty function in the success or error handler function of the aja call with the customisation and message which you want to display