Attribute | Type | Default value | Required | Description |
url | string | - | Yes | Developer Server Interface Address |
data | string/object/ArrayBuffer | - | No | Parameters of the Request |
header | Object | - | No | Sets the request's header, but Referer is not allowed to be set in the header. The default content-type is application/json. |
method | string | GET | No | HTTP request method |
dataType | string | json | No | Format of returned data |
responseType | string | text | No | Response Data Type |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
OPTIONS | HTTP Request OPTIONS |
GET | HTTP Request GET |
HEAD | HTTP Request HEAD |
POST | HTTP Request POST |
PUT | HTTP Request PUT |
DELETE | HTTP Request DELETE |
TRACE | HTTP Request TRACE |
CONNECT | HTTP Request CONNECT |
Value | Description |
json | The returned data is in JSON format. upon receipt, the data will undergo a JSON.parse operation. |
Other | The data will not undergo a JSON.parse operation. |
Value | Description |
text | Response data is text. |
arraybuffer | The response data is in ArrayBuffer format. |
Attribute | Type | Description |
data | string/Object/Arraybuffer | Data returned from the developer's server. |
statusCode | number | HTTP status code returned from the developer's server. |
header | Object | HTTP Response Header returned from the developer's server. |
GET
method, the data will be converted into a query string (encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...
).POST
method and where header['content-type']
is application/json
, the data will undergo JSON serialization.POST
method and where header['content-type']
is application/x-www-form-urlencoded
, the data will be converted into a query string (encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)
.wx.request({url: 'test.php', // This is merely an example and not an actual interface address.data: {x: '',y: ''},header: {'content-type': 'application/json' // Default value},success(res) {console.log(res.data)}})
This method is used via RequestTask.abort().
This method is used via RequestTask.onChunkReceived(function listener).
Attribute | Type | Description |
res | Object | The Response every time when a new chunk is returned from the developer's server. |
Structure attributes | Type | Description |
data | ArrayBuffer | Returned chunk buffer |
This method is used via RequestTask.offChunkReceived(function listener).
const listener = function (res) { console.log(res) }RequestTask.onChunkReceived(listener)RequestTask.offChunkReceived(listener) // The same function object as the listener must be passed in.
This method is used via RequestTask.onHeadersReceived(function listener).
const listener = function (res) { console.log(res) }RequestTask.onHeadersReceived(listener)RequestTask.offHeadersReceived(listener) // The same function object as the listener must be passed in.
This method is used via RequestTask.offHeadersReceived(function listener).
Attribute | Type | Description |
header | Object | HTTP Response Header returned from the developer's server. |
Was this page helpful?