建议使用ajax,比较成熟。jquery
fetch是比较新的接口,不少浏览器中已经有实现(实验性的)。若是浏览器不支持,可使用npm安装isomorphic-fetch
和whatwg-fetch
等polyfill。使用时直接:git
import 'whatwg-fetch'; // 或者 import 'isomorphic-fetch';
就可使用fetch了。github
可是,fetch自己不支持timeout,这意味着它必须等待到服务器有数据返回才会结束! https://github.com/whatwg/fetch/issues/20 是关于这个问题的讨论。ajax
固然,可使用一些比较复杂的技巧让fetch支持timeout,例如 http://stackoverflow.com/questions/38512238/how-to-add-a-settimeout-to-a-fetch-promise-that-uses-redux 中提供的代码。npm
React开发应用时,使用ajax也很简单。redux
$ npm install jquery --save
而后在你的ES6代码中导入:promise
import $ from 'jquery';