The DayPilot.Http.ajax() method makes an HTTP request to the specified URL.

The syntax and behavior is inspired by jQuery.ajax(). However, the default POST body format is JSON.

Available in DayPilot Pro for JavaScript since version 2018.2.3223. In previous versions, it is available as DayPilot.ajax().

This method is static.

Declaration

DayPilot.Http.ajax(options);

Parameters

  • options.url (string) - URL of the HTTP request

  • options.method ("POST" | "GET" | "PUT" | "DELETE") - request method. The default value is "GET". Since 2020.3.4578, if the method is not specified and options.data is present, "POST" is used.

  • options.data (optional) - request body. If the type of options.data is "object", the value is serialized using JSON.stringify().

  • options.contentType (string, optional) - request body content type. The default value is "application/json" if options.data is an object, or "text/plain" for other types.

  • options.success (optional) - success event handler

  • options.error (optional) - error event handler

Success Callback

The success callback is executed for HTTP status code 200, 201, 204, or 304 when any nonempty response body is valid JSON.

Arguments:

  • args.request - XMLHttpRequest object used for making the request

  • args.data - event data received from the server, converted from JSON to object using JSON.parse()

Error Callback

The error callback is executed for other HTTP status codes and, in Pro since version 2026.4.7086, malformed JSON in a nonempty response.

Arguments:

  • args.request - XMLHttpRequest object used for making the request

For JSON parsing failures, args.exception contains the parsing exception and args.request contains the original request. Empty successful responses are accepted with args.data undefined. This also applies to the DayPilot.ajax() alias. Collection loaders such as events.load() additionally require a JSON array and reject empty bodies.

Example

DayPilot.Http.ajax({
  url: "/events",
  success: (args) => {
    console.log("Data received:");
    console.log(args.data);
  }
});