The events.load() method loads events from a given URL using an AJAX call. The URL must return a JSON array with events that follow the DayPilot.Event.data structure.

Declaration

DayPilot.Month.events.load(url[, success[, error]]);

Parameters

  • url (string) - the URL

  • success (function) - success callback

  • error (function) - error callback

Notes

The HTTP call uses GET by default. The calendar adds start and end parameters that specify the visible start and end to the query string.

You can use DayPilot.Month.eventsLoadMethod to switch to POST.

The POST request sends the following parameters as a JSON object (since version 8.1):

  • start - visible start

  • end - visible end

Example POST body:

{"start": "2027-05-31T00:00:00", "end": "2027-07-05T00:00:00"}

The monthly calendar is updated automatically after a successful AJAX call. You can cancel the client-side refresh by calling args.preventDefault() in the success callback.

Success Callback

function success(args) {}

The success callback is executed only if the data is received successfully and parsed as a JSON array. It runs after the response is received but before the calendar is updated. Call args.preventDefault() to cancel the automatic update.

Arguments:

  • args.preventDefault() - cancels the automatic update

  • args.data (array) - event data received from the server

Error Callback

function error(args) {}

The error callback is executed for unsuccessful HTTP responses and invalid collection responses.

Arguments:

  • args.exception (object) - parsing or response-validation exception

  • args.request (XmlHttpRequest) - the request object used for the AJAX call

Invalid Responses

In Pro since version 2026.4.7086, an empty response body, malformed JSON, or valid JSON that is not an array invokes the error callback. Return [] for an empty collection; an empty body or null is not an empty collection.

args.request contains the original XMLHttpRequest, including for empty responses. args.exception contains the parsing or validation exception when applicable. Invalid responses do not call the success callback or replace the existing collection.

Example

Minimal call:

dp.events.load("/getEvents");

With callbacks:

This example loads events from /getEvents. The current date range is passed in the start and end query string parameters.

const success = (args) => {
  dp.message("Events loaded");
};

const error = (args) => {
  dp.message("Loading failed.");
};

dp.events.load("/getEvents", success, error);

Sample data returned from /getEvents:

[
  {
    "id": 1,
    "start": "2027-01-01T09:00:00",
    "end": "2027-01-01T13:00:00",
    "text": "Event 1",
    "cssClass": "my-event"
  },
  {
    "id": 2,
    "start": "2027-01-02T09:00:00",
    "end": "2027-01-02T13:00:00",
    "text": "Event 2"
  }
]

See Also

DayPilot.Event.data

DayPilot.Calendar.eventsLoadMethod

HTML5 Monthly Calendar and ASP.NET Core [code.daypilot.org]

DayPilot.Month Class

Availability

Availability of this API item in DayPilot editions:

ProductLitePro
DayPilot for JavaScript