The events.load() method loads events from a URL using an HTTP request. The endpoint must return a JSON array of event records that follow the DayPilot.Event.data structure.
Declaration
DayPilot.Calendar.events.load(url[, success[, error]])Parameters
url(string) - target URLsuccess(function) - callback executed after the response is received and parsed successfullyerror(function) - callback executed when the request fails or the response cannot be parsed
Notes
The request uses HTTP GET by default. The Calendar appends start and end query string parameters that describe the visible date range.
Use DayPilot.Calendar.eventsLoadMethod to switch the request method to POST.
When using POST, the request body contains a JSON object with the visible range (available since version 8.1):
{"start": "2027-06-15T09:00:00", "end": "2027-06-15T13:00:00"}The Calendar updates automatically after a successful request. 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 after the data is received successfully and parsed as a JSON array, but before the Calendar is updated.
Arguments:
args.preventDefault()- cancels the automatic Calendar updateargs.data(array) - event data returned by 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 exceptionargs.request(XmlHttpRequest) - 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 event handlers:
This example loads events from "/getEvents" and shows a message after the request completes.
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.Calendar.eventsLoadMethod
Event Loading [doc.daypilot.org]
Availability
Availability of this API item in DayPilot editions:
| Product | Lite | Pro |
|---|---|---|
| DayPilot for JavaScript |
DayPilot