Giter Site home page Giter Site logo

wxapp-xmlhttprequest's Introduction

wxapp-XMLHttpRequest

Greenkeeper badge Build Status Dependency License Prettier Node npm version

微信小程序的XMLHttpRequest实现

让你在微信小程序中使用Web(看起来)标准的Ajax接口调用

不建议生产环境中使用,可以使用wxapp-httpwxapp-fetch

纯属学习...

Installation

npm install wxapp-XMLHttpRequest --save

example

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
  1. 打开微信web开发者工具, 加载wxapp-XMLHttpRequest/example目录
  2. 修改index.ts

欢迎PR.

You can flow Contribute Guide

Contributors


Axetroy

💻 🔌 ⚠️ 🐛 🎨

License

The MIT License

wxapp-xmlhttprequest's People

Contributors

axetroy avatar greenkeeper[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.