import WuhuBase from "../WuhuBase"; import Log from "../Log"; export default class FetchUtils extends WuhuBase { className = 'FetchUtils'; /** * 包装jquery ajax 异步返回string * @param url * @param method */ public ajax(url: string, method: 'GET' | 'POST'): Promise { return new Promise((res, rej) => { $.ajax({ method: method, url: url, success: function (data) { res(data) }, error: function (e) { rej(e) } }); }); } public fetchText(url: string, init: RequestInit = null): Promise { return new Promise((resolve, reject) => window.fetch(url, init) .then(res => res.text()) .then(t => resolve(t)) .catch(err => { Log.error('fetchText出错了', err); reject(err); }) ); } }