等待2个AJAX请求complet(d3.js)whit优化临时等待?(Waiting for 2 AJAX request to complet (d3.js) whit optimize the

编程入门 行业动态 更新时间:2024-10-27 02:28:54
等待2个AJAX请求complet(d3.js)whit优化临时等待?(Waiting for 2 AJAX request to complet (d3.js) whit optimize the temp waiting?)

在运行第一个请求的回调函数RUN_ACTIONS()之前我需要2个ajax请求是complet,但是如何等待它(whit优化临时等待)?

function ajax() { d3.tsv( ajaxUrl, function(data) { while (!secondAJAXQueryComplet()); RUN_ACTIONS(HEADER, data); } ); d3.json( ajaxUrl, function(header) { define_Header(header); } ); }

I need 2 ajax request are complet before run the callback function RUN_ACTIONS() of the first request, but how waiting it ( whit optimize the temp waiting )?

function ajax() { d3.tsv( ajaxUrl, function(data) { while (!secondAJAXQueryComplet()); RUN_ACTIONS(HEADER, data); } ); d3.json( ajaxUrl, function(header) { define_Header(header); } ); }

最满意答案

你没有这样做,你使用一般的回调概念:

function dostuff(callWhenDone) { // ... d3.tsv(ajaxUrl, function callWhenTSVCompletes(data) { // ... d3.json(ajaxUrl, function callWhenJSONCompletes(header) { //... callWhenDone(); // now we're done. }); }); }

With this code i run the 2 AJAX Query simultanious and wait the last answer before run my callback function RUN_ACTIONS(). but this method does not seem to me very elegant

function ajax() { var ready=false, datatsv=false; d3.tsv( ajaxUrl, function(data) { if (ready) RUN_ACTIONS(HEADER, data); else { ready=true; datatsv=data; } } ); d3.json( ajaxUrl, function(header) { define_Header(header); if (ready) RUN_ACTIONS(header, datatsv); else { ready=true; } } ); }

更多推荐

本文发布于:2023-08-07 14:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464773.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:js   whit   AJAX   complet   temp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!