Use XMLHttpRequest (XHR) objects to interact with servers. You can retrieve data from a URL without having to do a full page refresh. This enables a Web page to update just part of a page without disrupting what the user is doing.

Documentation XMLHttpRequest by Mozilla Contributors, licensed under CC-BY-SA 2.5.

See also:

Static variables

@:value(4)staticinlineread onlyDONE:Int = 4

@:value(2)staticinlineread onlyHEADERS_RECEIVED:Int = 2

@:value(3)staticinlineread onlyLOADING:Int = 3

@:value(1)staticinlineread onlyOPENED:Int = 1

@:value(0)staticinlineread onlyUNSENT:Int = 0

Constructor

new(ignored:String)

new(?params:Dynamic)

Throws:

null

DOMError

Variables

onreadystatechange:Function

An EventHandler that is called whenever the readyState attribute changes.

read onlyreadyState:Int

Returns an unsigned short, the state of the request.

read onlyresponse:Dynamic

Returns an ArrayBuffer, Blob, Document, JavaScript object, or a DOMString, depending on the value of XMLHttpRequest.responseType. that contains the response entity body.

read onlyresponseText:String

Returns a DOMString that contains the response to the request as text, or null if the request was unsuccessful or has not yet been sent.

responseType:XMLHttpRequestResponseType

Is an enumerated value that defines the response type.

read onlyresponseURL:String

Returns the serialized URL of the response or the empty string if the URL is null.

read onlyresponseXML:HTMLDocument

Returns a Document containing the response to the request, or null if the request was unsuccessful, has not yet been sent, or cannot be parsed as XML or HTML.

read onlystatus:Int

Returns an unsigned short with the status of the response of the request.

read onlystatusText:String

Returns a DOMString containing the response string returned by the HTTP server. Unlike XMLHTTPRequest.status, this includes the entire text of the response message ("200 OK", for example).

timeout:Int

Is an unsigned long representing the number of milliseconds a request can take before automatically being terminated.

read onlyupload:XMLHttpRequestUpload

Is an XMLHttpRequestUpload, representing the upload process.

withCredentials:Bool

Is a Boolean that indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies or authorization headers.

Methods

abort():Void

Aborts the request if it has already been sent.

Throws:

null

DOMError

getAllResponseHeaders():String

Returns all the response headers, separated by CRLF, as a string, or null if no response has been received.

Throws:

null

DOMError

getResponseHeader(header:String):String

Returns the string containing the text of the specified header, or null if either the response has not yet been received or the header doesn't exist in the response.

Throws:

null

DOMError

open(method:String, url:String, async:Bool, ?user:String, ?password:String):Void

open(method:String, url:String):Void

Initializes a request. This method is to be used from JavaScript code; to initialize a request from native code, use openRequest() instead.

Throws:

null

DOMError

overrideMimeType(mime:String):Void

Overrides the MIME type returned by the server.

Throws:

null

DOMError

send(?body:HTMLDocument):Void

send(?body:Blob):Void

send(?body:ArrayBufferView):Void

send(?body:ArrayBuffer):Void

send(?body:FormData):Void

send(?body:URLSearchParams):Void

send(?body:String):Void

Sends the request. If the request is asynchronous (which is the default), this method returns as soon as the request is sent.

Throws:

null

DOMError

setRequestHeader(header:String, value:String):Void

Sets the value of an HTTP request header. You must call setRequestHeader()after open(), but before send().

Throws:

null

DOMError

Inherited Variables

Inherited Methods

Defined by EventTarget

addEventListener(type:String, listener:Function, ?options:EitherType<AddEventListenerOptions, Bool>, ?wantsUntrusted:Bool):Void

addEventListener(type:String, listener:EventListener, ?options:EitherType<AddEventListenerOptions, Bool>, ?wantsUntrusted:Bool):Void

Register an event handler of a specific event type on the EventTarget.

Throws:

null

DOMError

dispatchEvent(event:Event):Bool

Dispatch an event to this EventTarget.

Throws:

null

DOMError

removeEventListener(type:String, listener:Function, ?options:EitherType<EventListenerOptions, Bool>):Void

removeEventListener(type:String, listener:EventListener, ?options:EitherType<EventListenerOptions, Bool>):Void

Removes an event listener from the EventTarget.

Throws:

null

DOMError