-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It doesn't work with JavaScript's "fetch" api #17
Comments
After hours of exploring, (According to this line below):
I finally found out that you need to add this line to each request's header in order to be identified as a Notyf request: 'X-Requested-With': 'Notyf' and then, copy and modify just the first two lines of the method below:
to this: function getResponseHeadersFETCH(response) {
var notificationHeader = response.headers.get("X-Notyf-Notifications"); // <-- Just this line has been modified.
if (notificationHeader !== null) {
notificationHeader = notificationHeader.split("\n");
notificationHeader.forEach(function (header) {
header = header.split(": ");
var key = header.shift();
if (key.length == 0) return;
var decodedData = decodeURIComponent(key);
var notifications = JSON.parse(decodedData);
notifications.forEach(function (notification) {
if (notification.type == 0) {
toastNotifySuccess(notification.message.replace(/\+/g, ' '), notification.duration);
}
else if (notification.type == 1) {
toastNotifyError(notification.message.replace(/\+/g, ' '), notification.duration);
}
else if (notification.type == 2) {
toastNotifyWarning(notification.message.replace(/\+/g, ' '), notification.duration);
}
else if (notification.type == 3) {
toastNotifyInformation(notification.message.replace(/\+/g, ' '), notification.duration);
}
else if (notification.type == 4) {
toastNotifyCustom(
notification.message.replace(/\+/g, ' '),
notification.duration,
notification.backgroundColor,
notification.icon);
}
})
});
}
} then, call this function after each request manually. It's not a good idea, but can solve the problem temporarily. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am using asynchronous 'fetch' to send requests. The endpoint actions call the "_notyfService.Success" method, but the notyf doesn't work and it is not displayed on the screen.
JS code:
let response = await fetch('/controller/action');
and in Controller's action, I have:
_notyfService.Success("Text"); return new EmptyResult();
Any suggestion?
The text was updated successfully, but these errors were encountered: