W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
從基礎(chǔ)庫 1.0.0 開始支持,這是一個異步方法。
發(fā)起一個 HTTP 請求。網(wǎng)絡(luò)相關(guān)的 API 在使用前需要配置域名白名單。請參考網(wǎng)絡(luò)請求使用說明
名稱 | 數(shù)據(jù)類型 | 屬性 | 默認(rèn)值 | 描述 |
---|---|---|---|---|
url | string | required | N/A | 請求地址 |
header | object | optional | {'content-type': 'application/json'}
|
請求 Header |
method | string | optional | GET
|
請求方法 |
data | object / string / arraybuffer | optional | null
|
請求數(shù)據(jù) |
dataType | string | optional | json
|
請求數(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)用成功、失敗都會執(zhí)行) |
值 | 說明 |
---|---|
GET | |
POST | |
OPTIONS | |
PUT | |
HEAD | |
DELETE |
值 | 說明 |
---|---|
json | 返回的數(shù)據(jù)為 JSON,返回后會對返回的數(shù)據(jù)進(jìn)行一次 JSON.parse |
其他 | 不對返回的內(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 | 返回數(shù)據(jù) |
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號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: