1.2.0 • Published 4 years ago

xfe-ajax v1.2.0

Weekly downloads
2
License
MIT
Repository
-
Last release
4 years ago

描述

  • ajax极简实现,取鉴自axios库,支持基本用法和链式用法,更多使用可参考examples示例

特性

  • 简单,轻量,无依赖
  • 兼容chrome、firfox、IE8+
  • 支持headers和xsrf设置
  • 支持上传,下载

快速上手

安装

npm install xfe-ajax --save

引入

import Ajax from "xfe-ajax"; // 模块引入

<script src='ajax.js'></script> // 直接引入

基本使用

var ajax = Ajax({
    method: 'post',
    url: '/base/post',
    data: {
        a: 1,
        b: 2
    }
    before: function (config) {
        console.log(config)
        return false;   // 取消请求
    },
    after: function (response) {
        console.log(response)
    },
    error: function (error) {
        console.log(error)
    }
})

ajax.abort(); // 取消请求

链式使用

import Ajax from "xfe-ajax"; // 模块引入
import AjaxDeferred from "./deferred-ajax"; // 模块引入

<script src='ajax.js'></script> // 直接引入
<script src='deferred-ajax.js'></script> // 直接引入

var Http = AjaxDeferred.proxy(Ajax);

var http = Http({
    method: 'get',
    url: '/base/get',
    params: {
        foo: {
            bar: 'baz'
        }
    },
    before: function (config) {
        console.log('before', config)
        return false;   // 取消请求
    },
    after: function (response) {
        console.log('after', response)
    },
    error: function (error) {
        console.log('error', error)
    },
}).done(function (response) {
    console.log('done-response', response)
}).fail(function (error) {
    console.log('fail-error', error)
});

http.abort(); // 取消请求
1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.9.9

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.8.9

4 years ago

0.8.8

4 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.6

4 years ago

0.8.7

4 years ago

0.9.5

4 years ago

0.9.0

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.8.5

4 years ago

0.8.4

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago