PythonMonkey: XMLHttpRequest Class Reference
Public Member Functions | |
| get | _requestMetadata () |
| 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 | |
| this this | request (this.#requestMethod, this.#requestURL.toString(), this.#requestHeaders, this.#requestBody ?? '', this.timeout, processRequestBodyChunkLength, processRequestEndOfBody, processResponse, processBodyChunk, processEndOfBody,()=>(this.#timedOutFlag=true),()=>(this.#response=null), this.#debug.bind(this),).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 |
| 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 |
Implement the XMLHttpRequest API (XHR for short) according to the spec.
- See also
- https://xhr.spec.whatwg.org/
◆ _requestMetadata()
| get XMLHttpRequest::_requestMetadata | ( | ) |
The unique connection id to identify each XHR connection when debugging Wrapper to print debug logs with connection id information
- Parameters
-
{string} selector Allowing others to inspect the internal properties
◆ abort()
| XMLHttpRequest::abort | ( | ) |
◆ 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
- 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 | ) |
◆ 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
◆ readyState()
| get XMLHttpRequest::readyState | ( | ) |
Returns client's state.
◆ request()
| this this XMLHttpRequest::request | ( | this.# | requestMethod, |
| this.#requestURL. | toString(), | ||
| this.# | requestHeaders, | ||
| this.#requestBody ?? '' | , | ||
| this. | timeout, | ||
| processRequestBodyChunkLength | , | ||
| processRequestEndOfBody | , | ||
| processResponse | , | ||
| processBodyChunk | , | ||
| processEndOfBody | , | ||
| () | , | ||
| (this.#timedOutFlag=true) | , | ||
| () | , | ||
| (this.#response=null) | , | ||
| this.#debug. | bindthis | ||
| ) |
◆ response()
| return this get XMLHttpRequest::response | ( | ) |
◆ 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 | ( | ) |
◆ 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.
◆ withCredentials() [2/2]
| set XMLHttpRequest::withCredentials | ( | flag | ) |
◆ DONE [1/2]
◆ DONE [2/2]
◆ 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]
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) =>
{
this.#debug('xhr:response')(`recv chunk, ${bytes.length} bytes «${trunc(bytes, 100)}»`);
this.#receivedBytes.push(bytes);
}
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
this dispatchEvent(new ProgressEvent('loadstart', { loaded:0, total:0 }))
let responseLength
Definition XMLHttpRequest.js:371
static LOADING
Definition XMLHttpRequest.js:141
static HEADERS_RECEIVED
Definition XMLHttpRequest.js:140
◆ processEndOfBody
const XMLHttpRequest::processEndOfBody
Initial value:
= () =>
{
this.#debug('xhr:response')(`end of body, received ${this.#receivedLength} bytes`);
const transmitted = this.#receivedLength;
this.#sendFlag = false;
for (const eventType of ['load', 'loadend'])
}
static DONE
Definition XMLHttpRequest.js:142
◆ processRequestBodyChunkLength
const XMLHttpRequest::processRequestBodyChunkLength
Initial value:
= ( bytesLength) =>
{
if (this.#uploadListenerFlag)
}
let requestBodyTransmitted
Definition XMLHttpRequest.js:344
let requestBodyLength
Definition XMLHttpRequest.js:345
◆ processRequestEndOfBody
const XMLHttpRequest::processRequestEndOfBody
Initial value:
= () =>
{
this.#uploadCompleteFlag = true;
if (!this.#uploadListenerFlag)
return;
for (const eventType of ['progress', 'load', 'loadend'])
}
◆ processResponse
const XMLHttpRequest::processResponse
◆ 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:
- python/pythonmonkey/builtin_modules/XMLHttpRequest.js
Public Member Functions inherited from