发送ajax请求到后台获取的数据不能显示到弹框中,怎么办?

2024-11-23 14:57:49
推荐回答(1个)
回答1:

异步引起的问题。你应该在success函数最后把拼接好的html显示在div中,然后再显示。

做法:定义好一个带有表头的空表格,隐藏它,待加载完数据再显示即可。


表头

$.ajax({
type: "POST",
url: "<%=path %>/two",
dataType: "json",
data:{'liDu':liDu,'startTime':startTime,'endTime':endTime},
success: function(returnedData){
var html = "";
var tdHead = "
";
var tdFoot = "
";
$("#t2 tr:gt(0)").remove();//每次刷新,但是不移除表头第一行。
for(var i=0;i var countInfo = returnedData[i];
var totalCount = countInfo.totalCount;
var sucCount = countInfo.sucCount;
var failCount = countInfo.failCount;
var unknowCount = countInfo.unknowCount;
var sucPercent = countInfo.sucPercent;
var failPercent = countInfo.failPercent;
var unknowPercent = countInfo.unknowPercent;
var countTimeZone = countInfo.countTimeZone;
html += "" + tdHead + (i + 1) + tdFoot +
tdHead + totalCount + tdFoot +
tdHead + sucCount + tdFoot +
tdHead + sucPercent + tdFoot +
tdHead + failCount + tdFoot +
tdHead + failPercent + tdFoot +
tdHead + unknowCount + tdFoot +
tdHead + unknowPercent + tdFoot +
tdHead + countTimeZone + tdFoot + "";
}
$("#t2").append(html);
$("#t2").show("slow");//我这是一个表格。
}
});