PythonMonkey   v0.7.2 (dev)
Loading...
Searching...
No Matches
XMLHttpRequest Class Reference
Inheritance diagram for XMLHttpRequest:
[legend]
Collaboration diagram for XMLHttpRequest:
[legend]

Public Member Functions

get readyState ()
 
 open (method, url, async=true, username=null, password=null)
 
 setRequestHeader (name, value)
 
get withCredentials ()
 
set withCredentials (flag)
 
get upload ()
 
 send (body=null)
 
this dispatchEvent (new ProgressEvent('loadstart', { loaded:0, total:0 }))
 
 if (!this.#uploadCompleteFlag &&this.#uploadListenerFlag) this. if(this. return
 
 debug ('xhr:send')(`$
 
 debug ('xhr:headers')('headers='+Object.entries(this.#requestHeaders))
 
 request (this.#requestMethod, this.#requestURL.toString(), this.#requestHeaders, this.#requestBody ?? '', this.timeout, processRequestBodyChunkLength, processRequestEndOfBody, processResponse, processBodyChunk, processEndOfBody,()=>(this.#timedOutFlag=true),()=>(this.#response=null),).catch((e)
 
 if (this.#timedOutFlag) return this. if(this. return this. else return this. }
 
 abort ()
 
get responseURL ()
 
get status ()
 
get statusText ()
 
 getResponseHeader (name)
 
 getAllResponseHeaders ()
 
 overrideMimeType (mime)
 
get responseType ()
 
set responseType (t)
 
return this get response ()
 
get responseText ()
 
get responseXML ()
 
 for (const chunk of this.#receivedBytes)
 
- Public Member Functions inherited from EventTarget
 addEventListener (type, listener)
 
 removeEventListener (type, listener)
 
 dispatchEvent (event)
 
 _hasAnyListeners ()
 
 _hasListeners (type)
 

Public Attributes

 onreadystatechange = null
 
 UNSENT = 0
 
 OPENED = 1
 
 HEADERS_RECEIVED = 2
 
 LOADING = 3
 
 DONE = 4
 
 timeout = 0
 
let requestBodyTransmitted = 0
 
let requestBodyLength = this.#requestBody ? this.#requestBody.length : 0
 
const processRequestBodyChunkLength
 
const processRequestEndOfBody
 
let responseLength = 0
 
const processResponse
 
const processBodyChunk
 
const processEndOfBody
 
 $ {this.#requestURL.href}`)
 
 get
 
const merged = new Uint8Array(this.#receivedLength)
 
return merged
 
- Public Attributes inherited from XMLHttpRequestEventTarget
 onloadstart
 
 onprogress
 
 onabort
 
 onerror
 
 onload
 
 ontimeout
 
 onloadend
 

Static Public Attributes

static UNSENT = 0
 
static OPENED = 1
 
static HEADERS_RECEIVED = 2
 
static LOADING = 3
 
static DONE = 4
 

Detailed Description

Implement the XMLHttpRequest API (XHR for short) according to the spec.

See also
https://xhr.spec.whatwg.org/

Member Function Documentation

◆ abort()

XMLHttpRequest::abort ( )

Cancels any network activity.

See also
https://xhr.spec.whatwg.org/#the-abort()-method

◆ debug() [1/2]

XMLHttpRequest::debug ( 'xhr:headers'  )

◆ debug() [2/2]

XMLHttpRequest::debug (   'xhr:send')

◆ dispatchEvent()

this XMLHttpRequest::dispatchEvent ( new   ProgressEvent 'loadstart', { loaded:0, total:0 })

◆ for()

XMLHttpRequest::for ( const chunk of this.#  receivedBytes)

◆ getAllResponseHeaders()

XMLHttpRequest::getAllResponseHeaders ( )
Returns
{string} all the response headers, separated by CRLF, as a string, or returns null if no response has been received.

◆ getResponseHeader()

XMLHttpRequest::getResponseHeader (   name)
Parameters
{string}name
Returns
{string} the text of a particular header's value

◆ if() [1/2]

XMLHttpRequest::if ( !this.#uploadCompleteFlag &&this.#  uploadListenerFlag)

◆ if() [2/2]

XMLHttpRequest::if ( this.#  timedOutFlag)
See also
https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send step 12
https://xhr.spec.whatwg.org/#handle-errors
Parameters
{Error}e
See also
https://xhr.spec.whatwg.org/#request-error-steps
Parameters
{string}event event type
{DOMException}exception

◆ open()

XMLHttpRequest::open (   method,
  url,
  async = true,
  username = null,
  password = null 
)

◆ overrideMimeType()

XMLHttpRequest::overrideMimeType (   mime)

Acts as if the Content-Type header value for a response is mime.
(It does not change the header.)

Parameters
{string}mime

◆ readyState()

get XMLHttpRequest::readyState ( )

Returns client's state.

◆ request()

XMLHttpRequest::request ( this.#  requestMethod,
this.#requestURL.  toString(),
this.#  requestHeaders,
this.#requestBody ?? ''  ,
this.  timeout,
processRequestBodyChunkLength  ,
processRequestEndOfBody  ,
processResponse  ,
processBodyChunk  ,
processEndOfBody  ,
()  ,
(this.#timedOutFlag=true)  ,
()  ,
(this.#response=null)   
)

◆ response()

return this get XMLHttpRequest::response ( )
See also
https://xhr.spec.whatwg.org/#text-response
Returns
{string} Returns the response body.
See also
https://xhr.spec.whatwg.org/#the-response-attribute

◆ responseText()

get XMLHttpRequest::responseText ( )

Returns response as text.

◆ responseType() [1/2]

get XMLHttpRequest::responseType ( )

◆ responseType() [2/2]

set XMLHttpRequest::responseType (   t)

◆ responseURL()

get XMLHttpRequest::responseURL ( )
Returns
{string}

◆ responseXML()

get XMLHttpRequest::responseXML ( )

Returns the response as document.

◆ send()

XMLHttpRequest::send (   body = null)

◆ setRequestHeader()

XMLHttpRequest::setRequestHeader (   name,
  value 
)

Combines a header in author request headers.

Parameters
{string}name
{string}value

◆ status()

get XMLHttpRequest::status ( )
Returns
{number} HTTP status code

◆ statusText()

get XMLHttpRequest::statusText ( )
Returns
{string} HTTP status message

◆ upload()

get XMLHttpRequest::upload ( )

Returns the associated XMLHttpRequestUpload object.
It can be used to gather transmission information when data is transferred to a server.

◆ withCredentials() [1/2]

get XMLHttpRequest::withCredentials ( )

A boolean value that indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates.
Setting withCredentials has no effect on same-origin requests.

See also
https://xhr.spec.whatwg.org/#the-withcredentials-attribute

◆ withCredentials() [2/2]

set XMLHttpRequest::withCredentials (   flag)

Member Data Documentation

◆ $

XMLHttpRequest::$ {this.#requestURL.href}`)

◆ DONE [1/2]

XMLHttpRequest::DONE = 4
static

@readonly

◆ DONE [2/2]

XMLHttpRequest::DONE = 4

@readonly

◆ get

XMLHttpRequest::get
Initial value:
{
return this.#receivedBytes.reduce((sum, chunk) => sum + chunk.length, 0)

@type {Method} @type {URL} @type {{ [name: string]: string; }} @type {string | Uint8Array | null} @type {import('./XMLHttpRequest-internal').XHRResponse} @type {Uint8Array[]} @type {ResponseType} cache for converting receivedBytes to the desired response type @type {ArrayBuffer | string | Record<any, any>} Get received bytes’s total length

◆ HEADERS_RECEIVED [1/2]

XMLHttpRequest::HEADERS_RECEIVED = 2
static

@readonly

◆ HEADERS_RECEIVED [2/2]

XMLHttpRequest::HEADERS_RECEIVED = 2

@readonly

◆ LOADING [1/2]

XMLHttpRequest::LOADING = 3
static

@readonly

◆ LOADING [2/2]

XMLHttpRequest::LOADING = 3

@readonly

◆ merged [1/2]

const XMLHttpRequest::merged = new Uint8Array(this.#receivedLength)

Concatenate received bytes into one single Uint8Array

◆ merged [2/2]

return XMLHttpRequest::merged

◆ onreadystatechange

XMLHttpRequest::onreadystatechange = null

@type {EventListenerFn}

◆ OPENED [1/2]

XMLHttpRequest::OPENED = 1
static

@readonly

◆ OPENED [2/2]

XMLHttpRequest::OPENED = 1

@readonly

◆ processBodyChunk

const XMLHttpRequest::processBodyChunk
Initial value:
= ( bytes) =>
{
debug('xhr:response')(`recv chunk, ${bytes.length} bytes (${trunc(bytes, 100)})`);
this.#receivedBytes.push(bytes);
if (this.#state === XMLHttpRequest.HEADERS_RECEIVED)
this.#state = XMLHttpRequest.LOADING;
this.dispatchEvent(new Event('readystatechange'));
this.dispatchEvent(new ProgressEvent('progress', { loaded:this.#receivedLength, total:responseLength }));
}
function trunc(what, maxlen, coerce)
Definition XMLHttpRequest.js:26
const debug
Definition XMLHttpRequest.js:16
Definition event-target.js:18
Definition XMLHttpRequest.js:49
Definition XMLHttpRequest.js:102
$
Definition XMLHttpRequest.js:383
this dispatchEvent(new ProgressEvent('loadstart', { loaded:0, total:0 }))
let responseLength
Definition XMLHttpRequest.js:343
static LOADING
Definition XMLHttpRequest.js:113
static HEADERS_RECEIVED
Definition XMLHttpRequest.js:112

◆ processEndOfBody

const XMLHttpRequest::processEndOfBody
Initial value:
= () =>
{
debug('xhr:response')(`end of body, received ${this.#receivedLength} bytes`);
const transmitted = this.#receivedLength;
const length = responseLength || 0;
this.dispatchEvent(new ProgressEvent('progress', { loaded:transmitted, total:length }));
this.#state = XMLHttpRequest.DONE;
this.#sendFlag = false;
this.dispatchEvent(new Event('readystatechange'));
for (const eventType of ['load', 'loadend'])
this.dispatchEvent(new ProgressEvent(eventType, { loaded:transmitted, total:length }));
}
static DONE
Definition XMLHttpRequest.js:114
See also
https://xhr.spec.whatwg.org/#handle-response-end-of-body

◆ processRequestBodyChunkLength

const XMLHttpRequest::processRequestBodyChunkLength
Initial value:
= ( bytesLength) =>
{
requestBodyTransmitted += bytesLength;
if (this.#uploadListenerFlag)
this.#uploadObject.dispatchEvent(new ProgressEvent('progress', { loaded:requestBodyTransmitted, total:requestBodyLength }));
}
let requestBodyTransmitted
Definition XMLHttpRequest.js:316
let requestBodyLength
Definition XMLHttpRequest.js:317

◆ processRequestEndOfBody

const XMLHttpRequest::processRequestEndOfBody
Initial value:
= () =>
{
this.#uploadCompleteFlag = true;
if (!this.#uploadListenerFlag)
return;
for (const eventType of ['progress', 'load', 'loadend'])
this.#uploadObject.dispatchEvent(new ProgressEvent(eventType, { loaded:requestBodyTransmitted, total:requestBodyLength }));
}

◆ processResponse

const XMLHttpRequest::processResponse
Initial value:
= (response) =>
{
debug('xhr:response')(`response headers ----\n${response.getAllResponseHeaders()}`);
this.#response = response;
this.dispatchEvent(new Event('readystatechange'));
if (this.#state !== XMLHttpRequest.HEADERS_RECEIVED)
return;
responseLength = this.#response.contentLength;
}
return this get response()
Definition XMLHttpRequest.js:583

◆ requestBodyLength

let XMLHttpRequest::requestBodyLength = this.#requestBody ? this.#requestBody.length : 0

◆ requestBodyTransmitted

let XMLHttpRequest::requestBodyTransmitted = 0

◆ responseLength

let XMLHttpRequest::responseLength = 0

◆ timeout

XMLHttpRequest::timeout = 0

Timeout time in milliseconds.
When set to a non-zero value will cause fetching to terminate after the given time has passed.

◆ UNSENT [1/2]

XMLHttpRequest::UNSENT = 0
static

@readonly

◆ UNSENT [2/2]

XMLHttpRequest::UNSENT = 0

@readonly


The documentation for this class was generated from the following file: