AjaxResponse

class stable

A normalized response from an AJAX request. To get the data from the response, you will want to read the response property.

class AjaxResponse<T> {
  constructor(originalEvent: ProgressEvent<EventTarget>, xhr: XMLHttpRequest, request: AjaxRequest, type: any = 'download_load')
  get status: number
  get response: T
  get responseType: XMLHttpRequestResponseType
  get loaded: number
  get total: number
  get responseHeaders: Record<string, string>
  get originalEvent: ProgressEvent
  get xhr: XMLHttpRequest
  get request: AjaxRequest
  get type: AjaxResponseType
}

Description

  • DO NOT create instances of this class directly.
  • DO NOT subclass this class.

It is advised not to hold this object in memory, as it has a reference to the original XHR used to make the request, as well as properties containing request and response data.

Constructor

A normalized response from an AJAX request. To get the data from the response, you will want to read the response property.

constructor(originalEvent: ProgressEvent<EventTarget>, xhr: XMLHttpRequest, request: AjaxRequest, type: any = 'download_load')

Parameters

originalEvent

The original event object from the XHR onload event.

xhr

The XMLHttpRequest object used to make the request. This is useful for examining status code, etc.

request

The request settings used to make the HTTP request.

type

Optional. Default is 'download_load'.

The type of the event emitted by the ajax Observable

  • DO NOT create instances of this class directly.
  • DO NOT subclass this class.

Properties

Property Type Description
status number Read-only.

The HTTP status code

response T Read-only.

The response data, if any. Note that this will automatically be converted to the proper type

responseType XMLHttpRequestResponseType Read-only.

The responseType set on the request. (For example: "", "arraybuffer", "blob", "document", "json", or "text")

loaded number Read-only.

The total number of bytes loaded so far. To be used with total while calculating progress. (You will want to set includeDownloadProgress or includeDownloadProgress)

total number Read-only.

The total number of bytes to be loaded. To be used with loaded while calculating progress. (You will want to set includeDownloadProgress or includeDownloadProgress)

responseHeaders Record<string, string> Read-only.

A dictionary of the response headers.

originalEvent ProgressEvent Read-only.

The original event object from the raw XHR event.

The original event object from the XHR onload event.

Declared in constructor.
xhr XMLHttpRequest Read-only.

The XMLHttpRequest object used to make the request. NOTE: It is advised not to hold this in memory, as it will retain references to all of it's event handlers and many other things related to the request.

The XMLHttpRequest object used to make the request. This is useful for examining status code, etc.

Declared in constructor.
request AjaxRequest Read-only.

The request parameters used to make the HTTP request.

The request settings used to make the HTTP request.

Declared in constructor.
type AjaxResponseType Read-only.

The event type. This can be used to discern between different events if you're using progress events with includeDownloadProgress or includeUploadProgress settings in AjaxConfig.

The event type consists of two parts: the AjaxDirection and the the event type. Merged with _, they form the type string. The direction can be an upload or a download direction, while an event can be loadstart, progress or load.

download_load is the type of event when download has finished and the response is available.

See Also

© 2015–2021 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/ajax/AjaxResponse