Comparing version 3.1.0 to 3.2.0
@@ -1,5 +0,4 @@ | ||
var XMLHttpRequest = require('xhrpolyfill') | ||
module.exports = function xhr2 (params, callback) { | ||
var url = typeof params === 'string' ? params : params.url | ||
var method = params.method || (params.data ? 'POST': 'GET') | ||
var method = params.method || (params.data ? 'POST' : 'GET') | ||
var body = params.data | ||
@@ -10,4 +9,3 @@ var H = params.headers ? params.headers : params.body ? { | ||
} : {} | ||
var xhr = XMLHttpRequest() | ||
if (!xhr) throw new Error('No AJAX support') | ||
var xhr = new XMLHttpRequest() | ||
xhr.open(method, url) | ||
@@ -14,0 +12,0 @@ for (var key in H) xhr.setRequestHeader(key, H[key]) |
{ | ||
"name": "minixhr", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "super simpel and small cross-browser xhr", | ||
@@ -18,2 +18,3 @@ "main": "minixhr.js", | ||
"http", | ||
"request", | ||
"browser", | ||
@@ -28,6 +29,3 @@ "cross-browser", | ||
}, | ||
"homepage": "https://github.com/serapath/minixhr", | ||
"dependencies": { | ||
"xhrpolyfill": "^1.3.0" | ||
} | ||
"homepage": "https://github.com/serapath/minixhr" | ||
} |
@@ -8,25 +8,21 @@ # minixhr | ||
var callback = function responseHandler (data, response, xhr, header) { | ||
console.log(data) | ||
} | ||
// EXAMPLE 1 | ||
// response handler | ||
function callback (data, response, xhr, header) { console.log(data) } | ||
minixhr('http://jsonplaceholder.typicode.com/posts/1', callback) | ||
// check http://requestb.in/18b4srl1?inspect afterwards to inspect | ||
var data = { | ||
foo: 123, | ||
bar: "abc" | ||
} | ||
// EXAMPLE 2 | ||
var data = { foo: 123, bar: "abc" } | ||
var request = { // can be 'url string' or object: | ||
url : 'http://requestb.in/18b4srl1', | ||
method : 'POST', // [optional] (defaults to 'GET') | ||
data : JSON.stringify(data), // [optional] payload data could be <formdata> or {key:val}'s or anything | ||
headers : {} // [optional] (defaults to '{}' or in case of 'POST': | ||
// {'X-Requested-With':'XMLHttpRequest','Content-Type':'application/x-www-form-urlencoded' } ) | ||
/*required*/url : 'http://requestb.in/18b4srl1', | ||
/*optional*/method : 'POST', // (defaults to 'GET') | ||
/*optional*/data : JSON.stringify(data), // payload data could be <formdata> or {key:val}'s or any string | ||
/*optional*/headers : {} // (defaults to '{}' OR in case of 'POST' it defaults to: | ||
// {'X-Requested-With':'XMLHttpRequest','Content-Type':'application/x-www-form-urlencoded' } ) | ||
} | ||
minixhr(request) // [optional] callback - (e.g. leave out for POST Request where you don't care about a response | ||
``` | ||
// EXAMPLE 1 | ||
minixhr(request, callback) // [optional] callback - (e.g. leave out for POST Request where you don't care about a response | ||
// EXAMPLE 2 | ||
minixhr('http://jsonplaceholder.typicode.com/posts/1', callback) | ||
// check http://requestb.in/18b4srl1?inspect afterwards to inspect | ||
``` | ||
if you need to support old browsers, use version `3.1.0` or below. | ||
Those versions still include the [xhr polyfill](https://www.npmjs.com/package/xhrpolyfill) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3368
0
21
28
- Removedxhrpolyfill@^1.3.0
- Removedxhrpolyfill@1.4.1(transitive)