RequestTask.abort(function listener)
Introduction
Cancel a network request.
Parameters
function listener
A callback function for the result of the abort
operation.
Parameters
Object res
Attribute | Type | Description |
---|---|---|
success | string | true - successful false - failed |
errCode | string | Error code returned when the operation fails. |
errMsg | string | Error message returned when the operation fails. |
Explanation of errMsg
Error Message | Explanation |
---|---|
Http Request Abort Fail, callbackId is empty: R006 | Operation failed, request task not found |
Http Request Abort Fail, "+error+": R007 | Operation failed, error information |
Http Request Abort Fail, Exception_" + t.toString() +: R008 | Operation failed, exception information |
Sample Code
// pages/index/index.js
Page({
request() {
const requestTask = dlt.request({
url: "xxx",
data: JSON.stringify({ x: "xx" }),
header: JSON.stringify({
"content-type": "application/json",
}),
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
requestTask.abort(); // Cancel the request task
},
});