84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
如图,用ajax异步获取到了数据,怎么把数据返回到上一层。。。如图所示,怎么才能让第二个return的值是异步获取返回的数据
The person above is right, use promise
get:function(){ return new Promise(function(resolve,reject){ //ajax... $.post("test.php",function(response){ resolve(response) }) //如果有错的话就reject }) }
Use
get().then(function(response){ //response }).catch(function(err){ //错误处理 })
Either change it to synchronous or use callback, your return is useless
get:function(callback){ $.post(.....,function(res){ callback(res) }) } get(function(res){ console.log(res); })
Make it a Promise
return Promise.resolve($.post(url,data));
The person above is right, use promise
Use
Either change it to synchronous or use callback, your return is useless
Make it a Promise