A series of stream api. It provides a network request.
Start a network request, use two callbacks to receive server's response data.
method
, string, the HTTP method GET
or POST
.url
, string, the request url.headers
, string, the HTTP request headers.type
, string, response type, ‘json’,‘text’ or ‘jsonp’(same as ‘json’ in native implementation)body
, string, the HTTP body.::: warning
body
parameter only supports arguments of type string
. Do not use the JSON
format directly, you must convert it to a string.GET
request does not support arguments as body
. Please use the URL to set the parameters.Content-Type
is application/x-www-form-urlencoded
.JSON
format via POST, you need to set Content-Type
to application/json
. :::@callback, a callback function whose argument is the response object of the request. Callback function will receive a response
object.
status
, number, response status code.ok
, boolean, true if status code is bewteen 200~299.statusText
, string, status textdata
, string, response data. It's a object if request option is json
/jsonp
, or (string) in other type value.headers
, object, response headers.@progressCallback, function, a progress callback. This callback will be invoked before request finished.
readyState
, number, current request state.‘1’:request connection opened;‘2’:response headers received.;‘3’:response data is loading;status
, number, response status code.length
number, bytes of data have received. You can read full length of response from ‘headers’.statusText
, string, status text.headers
. object, response headers.::: tip
Demos