Namespace: request

just.request(urlnon-null, fnopt, optionsopt) → {*}

Make a request using XMLHttpRequest.
Since:
1.0.0-rc.23
Source:
core.js, line 1831

Parameters:

NameTypeDescription
url
urlSome url.
fn
[optional]
just.request~fnHook for onreadystatechange listener.
options
[optional]
object

Properties

NameTypeDefaultDescription
method
[optional]
string"GET"An HTTP Request Method: GET, POST, HEAD, ...
json
[optional]
boolean/.json$/.test(url)If true, "Content-Type" will be set to "application/json", #responseType to "json", and the #response/#responseText will be parsed to a JSON.
data
[optional]
AnynullData to send.
send
[optional]
functionjust.request~sendA custom function to intercept and send the request.
async
[optional]
booleantrue"async" param for XMLHttpRequest#open().
user
[optional]
stringnullUser name to use for authentication purposes.
pwd
[optional]
stringnullPassword to use for authentication purposes.
props
[optional]
objectjust.request~defaultPropsProperties for the xhr instance.
headers
[optional]
objectjust.request~defaultHeadersCustom headers for the request.

Returns:

The retuned value of just.request~send.
Type
Any

Methods

appendData(url, datanullable) → {string}

Append data to the search params of the given url.
Source:
core.js, line 1917
Parameters:
NameTypeDescription
url
stringSome url.
data
[nullable]
objectAn object to be appended.
Returns:
Type
string
Example
appendData('/some', {'data': 1}); // > '/some?data=1'
appendData('/some?url', {'data': 1}); // > '/some?url&data=1'

dataToUrl(datanullable) → {string}

Convert data into search params.
Source:
core.js, line 1945
Parameters:
NameTypeDescription
data
[nullable]
objectExpects an object literal.
Throws:
If data is not an object.
Type
TypeError
Returns:
Type
string
Example
dataToUrl({'a': '&a', 'b': 2}); // > 'a=%26&b=2'

Type Definitions

defaultHeaders

Default request headers.
Source:
core.js, line 1795
Properties:
NameTypeDefaultDescription
X-Requested-With
[optional]
string"XMLHttpRequest"
Content-Type
[optional]
string"application/json"Only on JSON requests.
Type:

object

defaultProps

Default request properties.
Source:
core.js, line 1802
Properties:
NameTypeDefaultDescription
responseType
[optional]
string"json"Only on JSON requests.
Type:

object

fn(errornullable, response)

A function to call on "load"/"error" event.
Source:
core.js, line 1786
This:

{XMLHttpRequest}

Parameters:
NameTypeDescription
error
[nullable]
ErrorBad status error or null.
response
AnyEither #response or #responseText property. On JSON request, the property parsed as a JSON.

send(data, optionsnon-null)

A function to intercept and send the request.
Source:
core.js, line 1778
This:

{XMLHttpRequest}

Parameters:
NameTypeDescription
data
AnyThe data ready to be sent.
options
objectThe options for the request.