gpt4 book ai didi

jQuery Ajax 查询在表格中显示列表

转载 作者:行者123 更新时间:2023-12-01 05:30:38 25 4
gpt4 key购买 nike

我认为图片可以更好地解释我的问题。

error

我需要这个(“Object Appel d'Offre:[La Fourniture et Installation]”)

仅显示一次。

jQuery 代码:

$(document).on("click","#bt_search",function (e) {
$.ajax({
url : '/Lots/Search',
type : 'POST',
dataType: 'json',
data : { RefAO : $("#RefAppelOffre").val() },
success : function(list) {
if(list == "fail"){

alert('error');

}
else{

$.each(list, function (i) {

$("#titreAppend").append("<h3 style='margin-top:55px'>Object Appel d'Offre : [ <u style='color:#f43030'><b> " + list[i].Objet + "</b></u> ] </h3>");
$("#tab tbody").append("<tr>" +
"<td>" + list[i].Ref_Lot + "</td>" +
"<td>" + list[i].Titre + "</td>" +
"<td>" + list[i].TotalLotTTC + "</td>" +
"<td>" + list[i].NombreConcurrent + "</td>" +
"<td>" + list[i].NombreArticle + "</td>" +
"</tr>");
})

}//Fermeture Else
}//Fermeture Success

})//fermeture ajax {}

})

Asp.net 返回代码:

[HttpPost]
public JsonResult Search(string RefAO)
{

var list = GlobalVariables.ctx.GetDetailedListLots(RefAO).ToList<GetDetailedListLots_Result>();
//var list = ctx.Bilan_Lot(RefAO).ToList<Bilan_Lot_Result>();
if(list != null)
{

return Json(list, JsonRequestBehavior.AllowGet);

}
else
{
return Json("fail");
}

}

我知道很明显我每次打印的标题都会被附加,有人能给我一个解决方案吗?

最佳答案

试试这个

$("#bt_search").click(function () {
$.ajax({
url : '/Lots/Search',
type : 'POST',
dataType: 'json',
data : { RefAO : $("#RefAppelOffre").val() },
success : function(list) {
if(list == "fail") {
alert('error');
}
else {
if (list.length) {
$("#titreAppend").append("<h3 style='margin-top:55px'>Object Appel d'Offre : [ <u style='color:#f43030'><b> " + list[0].Objet + "</b></u> ] </h3>");
}
$.each(list, function (i) {
$("#tab tbody").append("<tr>" +
"<td>" + list[i].Ref_Lot + "</td>" +
"<td>" + list[i].Titre + "</td>" +
"<td>" + list[i].TotalLotTTC + "</td>" +
"<td>" + list[i].NombreConcurrent + "</td>" +
"<td>" + list[i].NombreArticle + "</td>" +
"</tr>");
})

}//Fermeture Else
}//Fermeture Success

})//fermeture ajax {}
})

关于jQuery Ajax 查询在表格中显示列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37717099/

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