The events.load() method loads events from a URL using an HTTP GET or POST request, depending on eventsLoadMethod. The endpoint must return a JSON array of event records that follow the DayPilot.Event.data structure.

Declaration

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

Parameters

  • url (string) - URL of the API endpoint

  • success (function) - success callback

  • error (function) - error callback

Notes

For GET requests, the Scheduler adds the current view start and end values as query string parameters.

/getEvents?start=2027-06-15T09:00:00&end=2027-06-15T13:00:00

Use eventsLoadMethod to switch the request method to POST.

For POST requests, the current view start and end values are sent as a JSON object in the request body (since version 8.1):

{"start": "2027-06-15T09:00:00", "end": "2027-06-15T13:00:00"}

The Scheduler is updated automatically after a successful HTTP 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 only executed if the data is successfully received from the URL and it can be parsed as a JSON array.

Arguments:

  • args.preventDefault() - cancels the automatic Scheduler refresh

  • 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. When eventsLoadMethod is set to "POST", the current date range is sent in the request body as start and end.

dp.eventsLoadMethod = "POST";

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",
    "resource": "A",
    "cssClass": "my-event",
    "resizeDisabled": true
  },
  {
    "id": 2,
    "start": "2027-01-02T09:00:00",
    "end": "2027-01-02T13:00:00",
    "resource": "B",
    "text": "Event 2"
  }
]

See Also

DayPilot.Event.data

DayPilot.Scheduler.eventsLoadMethod

Event Loading [doc.daypilot.org]

DayPilot.Scheduler Class

Availability

Availability of this API item in DayPilot editions:

ProductLitePro
DayPilot for JavaScript