XMLHttpRequest 的超简单封装:xr
jopen
10年前
xr 是 XMLHttpRequest 的超简单封装,并返回 ES6 Promise。
特性
- Returns ES6 promises.
- Has query parameter generation.
- Supports events.
示例代码:
xr.get('/api/items', {take: 5}) .then(res => console.log(res.data)); xr.post('/api/item', {name: 'hello'}) .then(res => console.log("new item", res.data)); xr({ method: xr.Methods.GET, url: '/api/items', params: {take: 5}, events: { progress: (xhr, xhrProgressEvent) => { console.log("xhr", xhr); console.log("progress", xhrProgressEvent); } } });