After reloading the page, I want to display a toast notification confirming that the file has been uploaded. Here is my current code:
_fileUploads.delete = function(reload_on_return) {
var filtered = root.fileUploads().filter(_ => _._id() == _fileUploads._id());
var index = root.fileUploads.indexOf(filtered = filtered[0]);
filtered = ko.toJS(filtered);
swal({
text: 'Are you sure you want to delete this file?',
buttons: true,
dangerMode: true,
icon: 'warning'
}).then(function (allowDelete) {
if (allowDelete) {
$.ajax({
type: 'DELETE',
url: '/api/gridfs/files/' + filtered._id,
statusCode: {
204: function(response) {
toastrTrigger('The File has been Deleted')
if (reload_on_return) {
setTimeout( function() {
location.reload();
}, 0001);
}
}
},
error: function (xhr, status, error) {
console.log(xhr);
}
});
}
});
}
The page only refreshes and does not display the notification as intended.
Below is the code for the toastrtrigger function:
function toastrTrigger(message, title, type) {
setTimeout(function() {
toastr.options = {
closeButton: true,
progressBar: true,
showMethod: 'slideDown',
timeOut: 4000
};
toastr[type || "success"](message, title || 'File Uploads Repository');
}, 500);
}