Topic: Calendar error loading from serverside
I populate the calendar with items from our serverside API - items are returned as JSON. If there is a JSON error returned from the API, I want to catch the error and redirect to another page.
I cannot figure out how to access the error returned from the API - is there an onError method or something similar? What JSON format should the error data returned from the API take?
Mateusz Łubianka staff answered 5 years ago
To get data form API and call a function after catch an error you can use:
fetch('something.json').then(function(response) {
return response.json();
}).then(function(json) {
let result = json;
initialize(result);
}).catch(function(err) {
console.log('error');//your function after error
});
Best
Odhran pro premium priority commented 5 years ago
How does that integrate with the calendar control?
Mateusz Łubianka staff answered 5 years ago
When you get the data from the API, you can use js code from our examples and fill 'events' with your date and etc. https://mdbootstrap.com/plugins/jquery/full-calendar/#example
events: [{
title: title from API,
start: your date,
end: your date
},
Best,
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Pro
- Premium support: Yes
- Technology: MDB jQuery
- MDB Version: 4.8.9
- Device: laptop
- Browser: Chrome
- OS: Windows
- Provided sample code: No
- Provided link: No
Mateusz Łubianka staff commented 5 years ago
Hi,
please, create a snippet showing your problem here: https://mdbootstrap.com/snippets/. I'll try to help you.
Best,
Odhran pro premium priority commented 5 years ago
This is the jquery we are using to call our API, however the failure method is never called. https://mdbootstrap.com/snippets/jquery/odhran/1722052
The API returns this JSON if there is an error: {"success":false,"message":"Unauthorized"}