1.0.0 • Published 5 years ago

bestime-ajax v1.0.0

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

参数详解

参数类型必填默认描述
urlStringundefined请求的地址
dataObjectundefined发送的数据
successFunctionundefined成功回调
errorFunctionundefined失败回调
timeoutNumber1000 * 10超时时间,单位(毫秒)

实例化对象

参数类型描述
abortFunction终止ajax

GET请求

var demo = ajax({
  url: 'http://192.168.0.224:9997/get?name=bestime',
  data: {
    name: 'bestime',
    job: 'web前端',
    dp: [1,2]
  },
  timeout: 1000 * 10,
  success: function (res) {
    console.log('成功', res)
  },
  error: function (err) {
    console.log('失败', err)
  }
})

demo.abort(); // 可终止请求

POST请求

var demo = ajax({
  url: 'http://192.168.0.224:9997/post',
  type: 'POST',
  data: {
    name: 'bestime',
    job: 'web前端',
    other: ['张三', '李四', '王五']
  },
  success: function (res) {
    console.log('成功', res)
  },
  error: function (err) {
    console.log('失败', err)
  },
  timeout: 2000,
})

demo.abort(); // 可终止请求
1.0.0

5 years ago