Topic: Calendar error loading from serverside

Odhran priority asked 4 years ago


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 commented 4 years ago

Hi,

please, create a snippet showing your problem here: https://mdbootstrap.com/snippets/. I'll try to help you.

Best,


Odhran priority commented 4 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"}


Mateusz Łubianka staff answered 4 years ago


@Odhran,

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,


Mateusz Łubianka staff answered 4 years ago


@Odhran,

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 priority commented 4 years ago

How does that integrate with the calendar control?



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB jQuery
  • MDB Version: 4.8.9
  • Device: laptop
  • Browser: Chrome
  • OS: Windows
  • Provided sample code: No
  • Provided link: No