function a(){ return new Promise(function(res,rej){ $.ajax({ url:"a", type: "GET", async:true, dataType:"json", success:function(data){ console.log(data,"a"); res(data); } }) }); } function b(data){ console.log(data,"data"); return new Promise(function(res,rej){ $.ajax({ url:"b", type: "POST", async:true, data:JSON.stringify(data), dataType:"json", success:function(data){ console.log(data,"b"); res(); } }) }); } $("#btn").click(function(){ a().then(function (data){ b(data); }).then(function(){ }) })
b的请求结果依赖于a的数据
原文地址:https://www.cnblogs.com/celine-huang/p/11130942.html
时间: 2024-11-07 09:17:11