我正在使用 Jquery ajax。
我进行了 ajax 调用以获取数据并连接 html 字符串并附加到 div 的 id。
$("#divMenuList").html(JsMenuListHtml);
alert($("#divMenuList").html());
但是警报显示未定义。如果我是页面更改它第一次使用 html 字符串显示,但如果我将删除第二页记录并重新调用该函数,它将显示未定义,我有它使用列表。
这是整个功能:
function performlisting(data, JsCurrPage) {
var JsMenuTitle = '';
var JsOrderNumber = '';
var JsMenuId = '';
var JsMenuListHtml = '';
var JsCounter = 0;
var JsAlternateRow = '';
var JsIsActive = "false";
var JsIsActiveClass = "";
var JsIsActiveTitle = "";
if (data.Data.length > 0) {
for (i = 0; i < data.Data.length ; i++) {
JsCounter++;
if (JsCounter % 2 == 0) {
JsAlternateRow = "alternate-row";
}
else {
JsAlternateRow = '';
}
//set true/false for update status
if (data.Data[i]['IsActive'] == true) {
JsIsActive = "false";
JsIsActiveClass = "icon-3 info-tooltip";
JsIsActiveTitle = "Published";
}
else if (data.Data[i]['IsActive'] == false) {
JsIsActive = "true";
JsIsActiveClass = "icon-4 info-tooltip";
JsIsActiveTitle = "UnPublished";
}
else {
JsIsActive = "false";
JsIsActiveClass = "icon-4 info-tooltip";
JsIsActiveTitle = "UnPublished";
}
JsMenuTitle = data.Data[i]['MenuTitle'];
JsOrderNumber = data.Data[i]['OrderNumber'];
JsMenuId = data.Data[i]['MenuId'];
JsMenuListHtml = JsMenuListHtml +
'<tr class= ' + JsAlternateRow + '>' +
'<td style="width:3.4%;"><input type="checkbox" value=' + JsMenuId + ' /></td><td style="width:38.8%;">' + JsMenuTitle + '</td>' +
'<td style="width:39%;">' +
'<a title="Up-Rank" href="javascript:void(0);" onclick="return performUpMenu(\'' + JsOrderNumber + '\', \'' + JsMenuId + '\')"><img src=' + JsUpImage + '></a>' +
'<a title="Down-Rank" href="javascript:void(0);" onclick="return performDownMenu(\'' + JsOrderNumber + '\', \'' + JsMenuId + '\')"><img src=' + JsDownImage + '></a>' +
'' + JsOrderNumber + '</td>' +
'<td class="options-width"><a href="/Admin/Menu/AddEdit/' + JsMenuId + '/'+JsCurrPage+'" title="Edit Menu" class="icon-1 info-tooltip"></a>' +
'<a href="javascript:void(0);" onclick="return performdeletemenu(\'' + JsMenuId + '\');" title="Delete Menu" class="icon-2 info-tooltip"></a>' +
'<a href="javascript:void(0);" onclick="return performstatusmenu(\'' + JsIsActive + '\', \'' + JsMenuId + '\');" title= ' + JsIsActiveTitle + ' class=' + JsIsActiveClass + '></a>' +
'</td>' +
'</tr>';
}
$("#divMenuList").html("");
$("#divMenuList").html(JsMenuListHtml);
alert($("#divMenuList").html());
//hide num of raws dropdown
if (parseInt(JsTotalRecs) > parseInt(JsPageSize)) {
alert("Called1");
SetPaging(JsTotalRecs, parseInt(JsCurrPage));
}
else {
alert("Called");
$("#pager").html('');
}
$("#CurrPage").val(JsCurrPage);
SetAllCheckboxes();
}
else {
if ($("#CurrPage").val() > 1) {
//Error Message Pager
$("#product-table").html("");
$("#divSuccessMessage").html("");
alert(parseInt($("#CurrPage").val()));
GetListing(parseInt($("#CurrPage").val() - 1), parseInt(JsPageSize));
}
else {
$("#product-table").html("");
$("#divErrMessage").html("");
$("#divSuccessMessage").html("");
}
}
}
问候