js-transmission

1.1.6 • Public • Published

transmission.js@1.1.6

matters needing attention

Be based on Asynchronous Javascript And XML! In the future version, Access to Fetch API!

install transmission.js

 
npm install js-transmission --registry=https://registry.npm.taobao.org
 

use transmission.js

ES6 import

 
// For the sake of standardization, only support ES6 module!
import transmission from 'js-transmission';
 
transmission({
  url: "https://baidu.com",
  type: "GET",
  async: false,
  header: {
    'User-Agent': 'js-transmission'
  },
  data() {
    return {
      message: "hello transmission.js!"
    }
  },
  beforeSend() {
    // modify data
    return { // modify data
      message: "hello world!"
    }
  },
  sending() {
    //so do...
  },
  sent() {
    //so do...
  },
  inProcess() {
    //so do
  },
  beforeSuccess: (data, sendObject, ResponseHeaders) => {
    // data, sendObject, ResponseHeaders
    console.log(data)
    console.log(sendObject)
    console.log(ResponseHeaders)
  },
  success(response, headers) {
    // typeof response === 'object' //true
    console.dir(response),
    console.dir(headers)
  },
  error(error, statusData) {
    console.warn(error);
    console.dir(statusData)
  }
});
 
//GET example
 
transmission('https://baidu.com?search=transmission.js')
  .then(r => {
    console.dir(r)
  })
  .catch(e => {
    console.error(e)
})
 
//POST example
 
transmission({
  url: 'https://baidu.com',
  type: "POST",
  data:{message:"hello world!"}
})
.then(r => {
  console.dir(r)
})
.catch(e => {
  console.error(e)
})
 
 
 

License

MIT

transmission.js@1.1.6

Package Sidebar

Install

npm i js-transmission

Weekly Downloads

2

Version

1.1.6

License

MIT

Unpacked Size

18.9 kB

Total Files

6

Last publish

Collaborators

  • notescript