WebRequest

WebRequest uses XMLHttpRequest (XHR) to send and recieve messages with the server.

Constructor

new L3D.WebRequest(url, method, options)

new WebRequest(url, "GET", {
    responseType: "arraybuffer",
    onLoad: function(data) {
        _parseImage(data, texture);
    },
    onError: function(status) {
        console.error("Error requesting", url, ":", status);
    }
});
Parameters
url String

The URL to send the request to.

method String

The type of request to send. For example, "CREATE", "DELETE", "GET", "POST", or "PUT".

options Object

Options for the request.

Properties
responseType String

The type of data requested, such as "arraybuffer".

onLoad function

Callback when the return data has been recieved.

onError function

Callback for when there was an error with the request.

onAbort function

Callback for when the request was aborted.

onTimeout function

Callback for when the request timed out.

onLoadStart function

Callback for when loading has begun.

onLoadEnd function

Callback for when loading has finished.

onProgress function

Callback called while the data is still loading.

sync bool

If true, the request will be synchrounous and wait until the request has finished. Use this sparingly.

requestHeader Object
overrideMimeType String

Properties

headersRecieved bool

Have the request headers been recieved.

isDone bool

Has the request finished?

isError bool

Was there an error with the request?

isLoading bool

Is the request still on-going?

loadedBytes number

How many bytes have been recieved so far.

loadedPercent number

The percentage of the total bytes recieved so far.

method String

The method of the request.

readystate number

The xhr ready state.

response *

The xhr response.

responseText String

The xhr response text.

responseType number

The xhr response type.

status number

The xhr status.

statusText String

The xhr status text.

timeout number

How long to wait before considering the request timed out.

totalBytes number

How many bytes are expected to be recieved.

url String

The URL of the request.

xhr XMLHttpRequest

The underlying XMLHttpRequest object.

Methods

static Get(url, options)WebRequest

Send a GET request to the url. Shorthand for new WebRequest(url, WebRequest.GET, options).send().

Parameters
url String

The URL to send the request to.

options Object

See the constructor for the list of options.

Returns
WebRequest

static Head(url, options)WebRequest

Send a HEAD request to the url. Shorthand for new WebRequest(url, WebRequest.HEAD, options).send().

Parameters
url String

The URL to send the request to.

options Object

See the constructor for the list of options.

Returns
WebRequest

static Post(url, options, data)WebRequest

Send a POST request to the url. Shorthand for new WebRequest(url, WebRequest.POST, options).send(data).

Parameters
url String

The URL to send the request to.

options Object

See the constructor for the list of options.

data *

The data to post

Returns
WebRequest

static Put(url, options, data)WebRequest

Send a PUT request to the url. Shorthand for new WebRequest(url, WebRequest.PUT, options).send(data).

Parameters
url String

The URL to send the request to.

options Object

See the constructor for the list of options.

data *
Returns
WebRequest

abort()

Abort the request.

getAllResponseHeaders() → String

Get all of the xhr response headers.

Returns
String

getResponseHeader(name) → nullable String

Get the xhr response header with the given name.

Parameters
name Sting
Returns
String

overrideMimeType(mime)

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

Parameters
mime String

The mime type.

send(body) → WebRequst

Send the request.

Parameters
body *

The optional data to send.

Returns
WebRequst

Returns self.

setRequestHeader(header, value)

Set a request header value.

Parameters
header String
value String