wxapp-xmlhttprequest
v0.1.0
Published
Web XMLHttpRequest implement for WeChat APP
Downloads
4
Maintainers
Readme
wxapp-XMLHttpRequest
微信小程序的XMLHttpRequest实现
让你在微信小程序中使用Web(看起来)标准的Ajax接口调用
不建议生产环境中使用,可以使用wxapp-http或wxapp-fetch
纯属学习...
Installation
npm install wxapp-XMLHttpRequest --save
Usage
// es6
import XMLHttpRequest from 'wxapp-XMLHttpRequest';
// commonJS
const XMLHttpRequest = require('wxapp-XMLHttpRequest').default;
const request = new XMLHttpRequest();
console.dir(request);
request.timeout = 1000;
request.ontimeout = function(err) {
console.error(`request timeout`);
};
request.onerror = function(err) {
console.error(err);
};
request.onreadystatechange = e => {
console.log(e);
if (request.readyState === 4) {
console.log(request.status);
console.log(request.statusText);
console.log(request.getResponseHeader('Status'));
console.log(request.getAllResponseHeaders());
console.log(request.response);
this.setData({ response: request.response });
}
};
request.onabort = function() {
console.error(`request have been abort...`);
};
request.open('GET', 'https://api.github.com');
request.setRequestHeader('hello', 'world 123');
request.send('hello world');
// request.abort();
Related
wxapp-fetch fetch API implement for WeCHat App
wxapp-http 微信小程序的http模块,Tiny but Powerful
wxapp-r2 r2 implement in Wechat App client
Contributing
git clone https://github.com/axetroy/wxapp-XMLHttpRequest.git
cd ./wxapp-XMLHttpRequest
yarn
yarn run start
- 打开微信web开发者工具, 加载wxapp-XMLHttpRequest/example目录
- 修改index.ts
欢迎PR.
You can flow Contribute Guide
Contributors
| Axetroy💻 🔌 ⚠️ 🐛 🎨 | | :---: |
License
The MIT License