利用promise改造的ajax请求 可以跨域请求 也可以xml请求
Installation
You can install with npm
.
|
Usage
|
note:fetchPipe内的参数以对象的形式传进去,所传的参数规则同ajax一致
跨域请求
跨域请求一定要设定dataType:’jsonp’ ;
Set JSONP callback name, default is ‘callback’;
Set JSONP request timeout, default is 5000ms.
非跨域请求
非跨域请求 是按照dataType不是jsonp来判断的 则按照XMLHttpRequest进行请求
Caveats
You need to call .then(function(response) { return response.json(); })
in order
to keep consistent with Fetch API.
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
Latest ✔ | Latest ✔ | 8+ ✔ | Latest ✔ | 6.1+ ✔ |
实践
最新的版本加入了Object.assign 的兼容性 目前在手机端浏览器未发现其他问题 亲证可靠
例如像iphone4版本过低,不支持promise的,未兼容
License
MIT
Acknowledgement
Thanks to eastlee