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 data format is JSON.
Available in DayPilot Pro for JavaScipt since version 2018.2.3223. In previous versions, it's available as DayPilot.ajax().
Declaration
DayPilot.Http.ajax(options);
Parameters
- options.contentType - request body content type (string). Default value is "application/json" (if options.data is an object) or "text/plain" for other types.
- options.data - POST body (optional). If the type of options.data is "object" the value will be serialized using JSON.stringify().
- options.error - error event handler (optional)
- options.method - request method ("POST" | "GET" | "PUT" | "DELETE"). The default value is "GET". Since 2020.3.4578: If the method is not specified and options.data is present, "POST" is used.
- options.success - success event handler (optional)
- options.url - URL of the HTTP request
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 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: function(args) {
console.log("Data received:");
console.log(args.data);
}
});