W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
從基礎(chǔ)庫(kù) 1.0.0 開始支持,這是一個(gè)異步方法。
發(fā)起一個(gè) HTTP 請(qǐng)求。網(wǎng)絡(luò)相關(guān)的 API 在使用前需要配置域名白名單。請(qǐng)參考網(wǎng)絡(luò)請(qǐng)求使用說明
名稱 | 數(shù)據(jù)類型 | 屬性 | 默認(rèn)值 | 描述 |
---|---|---|---|---|
url | string | required | N/A | 請(qǐng)求地址 |
header | object | optional | {'content-type': 'application/json'} | 請(qǐng)求 Header |
method | string | optional | GET | 請(qǐng)求方法 |
data | object / string / arraybuffer | optional | null | 請(qǐng)求數(shù)據(jù) |
dataType | string | optional | json | 請(qǐng)求數(shù)據(jù)類型 |
responseType | string | optional | text | 響應(yīng)數(shù)據(jù)類型,參數(shù)值可以是text 或arraybuffer |
success | function | optional | 接口調(diào)用成功后的回調(diào)函數(shù) | |
fail | function | optional | 接口調(diào)用失敗后的回調(diào)函數(shù) | |
complete | function | optional | 接口調(diào)用結(jié)束后的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行) |
值 | 說明 |
---|---|
GET | |
POST | |
OPTIONS | |
PUT | |
HEAD | |
DELETE |
值 | 說明 |
---|---|
json | 返回的數(shù)據(jù)為 JSON,返回后會(huì)對(duì)返回的數(shù)據(jù)進(jìn)行一次 JSON.parse |
其他 | 不對(duì)返回的內(nèi)容進(jìn)行 JSON.parse |
值 | 說明 |
---|---|
text | 響應(yīng)的數(shù)據(jù)為文本 |
arraybuffer | 響應(yīng)的數(shù)據(jù)為 ArrayBuffer |
參數(shù)
Object res
名稱 | 數(shù)據(jù)類型 | 描述 |
---|---|---|
statusCode | number | 返回 HTTP 狀態(tài)碼 |
header | object | 返回 HTTP Header |
data | object / string / arraybuffer | 返回?cái)?shù)據(jù) |
RequestTask對(duì)象
let task = tt.request({
url: "someurl",
data: {
user_name: "hello"
},
header: {
"content-type": "application/json"
},
success(res) {
console.log(`request調(diào)用成功 ${res}`);
},
fail(res) {
console.log(`request調(diào)用失敗`);
}
});
if (someReason) {
task.abort();
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: