0.0.19 • Published 3 years ago

ajax-intercept-hook v0.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

gz-tool

XMLHTTPRequest 拦截功能

使用原型改写的方式进行拦截,对项目代码无侵入即可达到目的 目前笔者主要用来对项目中的接口耗时和接口错误进行统计!

使用方法

可以直接 script 标签引入 也可以使用 npm 安装使用

demo

script 引入方式

<script src="../lib/index.js"></script>
new GzTool.XMLHTTPRequestIntercept({
  openHook: (mothod, url, xhr) => {
    // 可以改写request url method
    console.log('openHook', mothod, url, xhr)
    return {
      url: 'https://my-json-server.typicode.com/typicode/demo/posts',
      method: 'POST'
    }
  },
  sendHook: (mothod, url, body, xhr) => {
    // 可以改写request body
    console.log('sendHook', mothod, url, xhr)
  },
  onreadyStateChangeHook: (mothod, url, xhr) => {
    console.log(mothod, url, xhr)
  },
  onreadyStateChange4Status200Hook: (mothod, url, xhr) => {
    console.log('onreadyStateChange4Status200Hook', mothod, url, xhr)
  }
})

npm 方式

npm install ajax-intercept-hook -S
import { XMLHTTPRequestIntercept } from 'ajax-intercept-hook'

// 使用方法同script引入
0.0.15

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.19

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago