This package has been migrated to @cycjimmy/mini-xhr for scoped NPM package. Please switch to @cycjimmy/mini-xhr to stay up to date.
# via npm
$ npm install mini-xhr --save
# or via yarn
$ yarn add mini-xhr
import miniXhr from 'mini-xhr';
# OR
const miniXhr = require('mini-xhr');
miniXhr.get(url [, settings])
.then((data) => {
// handle data
});
url
: [String] A string containing the URL to which the request is sent.- settings:
data
: [Object] The key-value pair that needs to be transmitted. Default{}
.dataType
: [String] Request data type. Default'json'
.contentType
: [String] Setting content type. Default'application/x-www-form-urlencoded; charset=UTF-8'
.timeout
: [Number] Set a timeout for the request. A value of 0 means there will be no timeout. Default0
.timeoutCB
: [Function] Set the time-out callback function. Defaultnull
.
url
: [String] A string containing the URL to which the request is sent.- settings:
data
: [Object] The key-value pair that needs to be transmitted. Default{}
.dataType
: [String] Request data type. Default'json'
.contentType
: [String] Setting content type. Default'application/x-www-form-urlencoded; charset=UTF-8'
.timeout
: [Number] Set a timeout for the request. A value of 0 means there will be no timeout. Default0
.timeoutCB
: [Function] Set the time-out callback function. Defaultnull
.
url
: [String] A string containing the URL to which the request is sent.- settings:
data
: [Object] The key-value pair that needs to be transmitted. Default{}
.timeout
: [Number] Set a timeout for the request. A value of 0 means there will be no timeout. Default0
.
url
: [String] A string containing the URL to which the request is sent.- settings:
data
: [Object] The key-value pair that needs to be transmitted. Default{}
.timeout
: [Number] Set a timeout for the request. A value of 0 means there will be no timeout. Default0
.
<script src="mini-xhr.min.js"></script>
<script>
miniXhr.jsonp('/getData' , {
data: {
key1: 'value1',
key2: 'value2',
}
})
.then(function(data) {
// data handle
});
</script>
To use via a CDN include this in your html:
<script src="https://cdn.jsdelivr.net/npm/mini-xhr@1/build/mini-xhr.min.js"></script>