串联或并联调用多个ajax请求 [英] Call Multiple ajax request in series or parallel
本文介绍了串联或并联调用多个ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3个功能.
load_graphs('national','','container-natl-rates','container-natl-counts')
load_graphs('division','Western','container-west-rates','container-west-counts')
load_graphs('division','Eatern','container-east-rates','container-east-counts')
load_graphs是执行ajax调用并创建图形的函数.
load_graphs is a function that performs a ajax call and creates a graph.
当前,此调用是异步完成的,但是我希望在完成每个单独的调用后像回叫一样执行.
Currently, this calls are done asynchronously but I want to perform like a call back after completing each individual calls.
推荐答案
使用诺言.
使用诺言是处理类似这样的事情的好方法,其中下一个任务需要上一个任务的值(或者至少要先完成上一个任务的值).
Using a promise is a great way to handle things like this where the next task requires a value from the previous task (or at least for the previous task to be completed first).
https://scotch.io/tutorials/javascript-promises-for-dummies
这篇关于串联或并联调用多个ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文