gpt4 book ai didi

javascript - 追加订单 - jQuery

转载 作者:行者123 更新时间:2023-12-02 19:51:04 25 4
gpt4 key购买 nike

我试图根据字符串的显示方式(红色、蓝色、橙色、黑色)来排序。由于某种原因,它会随机附加顺序。例如:它将输出(蓝色,橙色,红色,黑色)。任何帮助都会很棒。谢谢。

var tCookie = "red,blue,orange,black";
var Cookies = tCookie.split(',');

if (Cookies) {
for (var i = 1; i <= Cookies.length; i++) {

var dataString = "TabId="+Cookies[i]+"";

$.ajax({
type: "POST",
url: "includes/tab.php",
data: dataString,
cache: false,
success: function(html){
$("#Dynamic_Tab").append(html).children(':last').hide().fadeIn("fast");
}
});
}
}

最佳答案

您可以有一个请求和响应列表,并在所有操作完成后开始追加,以便顺序始终正确:

var deferreds = [],
results = [];

for (var i = 1; i <= Cookies.length; i++) {
(function(i) { // to freeze i

var dataString = "TabId="+Cookies[i]+"";

deferreds.push($.ajax({
type: "POST",
url: "includes/tab.php",
data: dataString,
cache: false,
success: function(html){
results[i] = html; // insert at the synchronous position
}
}));

})(i);
}

$.when.apply($, deferreds).then(function() {
$.each(results, function(i, html) {
$("#Dynamic_Tab").append(html).children(':last').hide().fadeIn("fast");
});
});

关于javascript - 追加订单 - jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9301527/

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