1.1.5 • Published 3 years ago

wl-httprequest v1.1.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

ajax请求插件

使用方法

npm install @stl/httprequset

import { http } from "@stl/httprequest"

http.get(
    {
        url:url,
        data:data,
        beforeSend:function(xhr:any){console.log("请求开始回调函数",xhr)},
        complete:function(xhr:any,status:any){console.log("请求结束回调函数",xhr,status)},
        ......
    }
).then(
    function(a:any){//请求成功的回调
        console.log(a)
    },
    function(e:any){//请求失败的回调
        console.log(e)
    }
)
或者
http.post(
    {
        url:url,
        data:data,
        beforeSend:function(xhr:any){console.log("请求开始回调函数",xhr)},
        complete:function(xhr:any,status:any){console.log("请求结束回调函数",xhr,status)},
    }
).then(
    function(a:any){//请求成功的回调
        console.log(a)
    },
).catch(
    function(e:any){//请求失败的回调
        console.log(e)
    }
)

方法说明

http.get();
http.post();调用此方法,参数data应为查询字符串或普通对象
http.put();
http.delete();
http.fromData();
http.postbody();//调用此方法,参数data应为json字符串

参数介绍

nametypedefaultdescription
urlstring""请求地址
typestring"GET"请求类型 GET POST DELETE
dataTypestring"json"返回的数据类型 json text document ...
asyncbooleantruetrue:异步请求 false:同步请求
dataobjectnull请求的参数
headersobject{}请求头
timeoutnumber10000请求超时时间
isFromdatabooleanfalse
beforeSendfunction(xhr:any) => { }请求开始回调函数
completefunction(xhr:any) => { }请求结束回调函数