1.0.1 • Published 5 years ago

ajax-j v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

一个小型的ajax库,提供开箱即用的ajax方法。

Install

npm install ajax-j

Usage

ajax({
    type:"post",
    url:"", //添加自己的接口链接
    timeOut:5000,
    before:function(data){
      console.log("请求发送的数据:"+data);  
    },
    success:function(response){
        console.log(response);
    },
    error:function(xhr){
        console.log("error:"+xhr.status);
    },
    complte:function(xhr){
        console.log("complte:"+xhr.status);
    }
});

Other Tool Method

// using es6 module
import ajaxJ from 'ajax-j'

ajaxJ.get(url,param,successCallback)
ajaxJ.post(url,param,successCallback)
//send post request, Content-Type is "application/json; charset=utf-8"
ajaxJ.postJson(url,param,successCallback) 

// or you can using promise
ajax.get(url,param).then(response=>{
    console.log(response)
}).catch(xhr=>{
    console.log(xhr)
})


// if import script direct, invoke method is:
get(url,param)
post(url,param)
postJson(url,param)

param table:

paramdefaultdesctype
url""请求的链接string
methodget请求的方法get,post,json
datanull请求的数据object,string,FormData,array
contentType""请求头string
dataType""请求的类型jsonp
asynctrue是否异步blooean
timeOutundefined超时时间number
beforefunction(data){}发送之前执行的函数function
successfunction(response){}请求成功的回调函数function
errorfunction(xhr){}请求报错执行的函数function
completefunction(xhr){}请求结束的回调函数function

min版本使用 javascript-minifier进行压缩

1.0.1

5 years ago

1.0.0

5 years ago