ajax-intercept-hook
TypeScript icon, indicating that this package has built-in type declarations

0.0.19 • Public • Published

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引入

Readme

Keywords

none

Package Sidebar

Install

npm i ajax-intercept-hook

Weekly Downloads

1

Version

0.0.19

License

MIT

Unpacked Size

38.1 kB

Total Files

10

Last publish

Collaborators

  • xx732395