function ajax(type, url, data, isJson) { return new Promise((resolve, reject) => { $.ajax({ type: type, url: url, dataType: ‘json‘, data: data, beforSend: function () { }, error: function (err) { reject(err.data) }, success: function (data) { resolve(data) } }); }) }
调用方法
ajax(‘post‘, url, {type: ‘1‘}).then(res => { console.log(‘请求成功‘) }).catch(() => { console.log(‘请求失败‘) })