Interface RequestOptions

interface RequestOptions {
    callback?: AjaxCallbackHandler;
    downloadFile?: string | boolean;
    failure?: AjaxHandler;
    form?: FormData | HTMLFormElement;
    headers?: Record<string, string>;
    initialConfig?: any;
    jsonData?: any;
    method?: string;
    params?: Record<string, any>;
    scope?: any;
    success?: AjaxHandler;
    timeout?: number;
    url: string;
}

Properties

A function called after any success/failure response is received. It will be passed the following arguments:

  • originalConfig: The config originally supplied to LABKEY.Ajax.request
  • success: boolean value that is true if the request was successful
  • xhr: The XMLHttpRequest where the text of the response can be found on xhr.responseText amongst other properties
downloadFile?: string | boolean

Save the response as a file. Only works in browser environments. When downloadFile is true, the download filename should be included in the response header (e.g. Content-Disposition: attachment; filename=data.xlsx) When downloadFile is a string, the download value will be used as the download filename. The success or failure functions will still be called.

failure?: AjaxHandler

A function called when a failure response is received (determined by XHR readyState, status, or ontimeout if supplied). It will be passed the following arguments:

  • xhr: The XMLHttpRequest where the text of the response can be found on xhr.responseText amongst other properties
  • originalConfig: The config originally supplied to LABKEY.Ajax.request
form?: FormData | HTMLFormElement

FormData or Object consumable by FormData that can be used to POST key/value pairs of form information. For more information, see FormData documentation.

headers?: Record<string, string>

Object specifying additional HTTP headers to add the request.

initialConfig?: any
jsonData?: any

Data provided to the XMLHttpRequest.send(data) function. If the request is method "POST" this is the body of the request.

method?: string

HTTP request method used for the XMLHttpRequest. Examples are "GET", "PUSH, "DELETE", etc. Defaults to "GET" unless jsonData is supplied then the default is changed to "POST". For more information, see this HTTP request method documentation.

params?: Record<string, any>

An object representing URL parameters that will be added to the URL. Note, that if the request is method "POST" and jsonData is not provided these params will be sent via the body of the request.

scope?: any

A scope for the callback functions. Defaults to "this".

success?: AjaxHandler

A function called when a successful response is received (determined by XHR readyState and status). It will be passed the following arguments:

  • xhr: The XMLHttpRequest where the text of the response can be found on xhr.responseText amongst other properties
  • originalConfig: The config originally supplied to LABKEY.Ajax.request
timeout?: number

If a non-null value is supplied then XMLHttpRequest.ontimeout will be hooked to failure.

url: string

The url used for the XMLHttpRequest. If you are making a request to the LabKey Server instance see buildURL for helpful URL construction.