HomeDocs
Skip to main content

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

AttributeTypeDescription
successstringtrue - successful
false - failed
errCodestringError code returned when the operation fails.
errMsgstringError message returned when the operation fails.

Explanation of errMsg

Error MessageExplanation
Http Request Abort Fail, callbackId is empty: R006Operation failed, request task not found
Http Request Abort Fail, "+error+": R007Operation failed, error information
Http Request Abort Fail, Exception_" + t.toString() +: R008Operation 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
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.