//1.封装 function getData(url , data = {
}) {
return new Promise((resolve , reject) = > {
$.ajax({
//发送请求 data: data sussess: function (res) {
resolve(res) }, error: function (res) {
reject(res) } }) }) } //2.使用 getData(url1) .then((res) => {
const {
id} = res return getData(url2 , {
id}) }) .then((res) => {
const {
name} = res return getData(url3 , {
name}) }) .then((res) => {
console.log(res) }) .catch((err) => {
console.log(err) })
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/225170.html原文链接:https://javaforall.net
