gpt4 book ai didi

javascript - javascript中do-while循环的用例?

转载 作者:行者123 更新时间:2023-11-30 16:12:32 25 4
gpt4 key购买 nike

我知道与必须满足运行条件的“while”相比,“do-while”至少会运行一次。

这是 do-while 的正确用例吗?

do{
var ajaxresponse = make an ajax call and assign the response to the variable.
while( ajaxresponse.length == <some number>);

最佳答案

对于响应数据的迭代和执行操作,最好在回调函数中进行。因为 AJAX 是异步的。以下代码使用 Jquery 进行 Ajax 请求。

$.ajax({
method: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( ajaxresponse ) {

do{
//operations
}while(ajaxresponse.length == <some number> );

});

关于javascript - javascript中do-while循环的用例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36026766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com