DayPilot.Http.ajax

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 when the response is received with HTTP status code 200, 201, 204, or 304.

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 when the response is received with an HTTP status code other than 200, 201, 204, or 304.

Arguments:

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

Example

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