使用Jquery重新加载内容表
我开发了一个表,在加载时使用PHP和mysql动态生成它的行。现在,我真正想要的是在单击按钮后使用Jquery仅刷新tbody元素。我已经写了在首都的评论,我想这样做。这是按钮的代码:使用Jquery重新加载内容表,jquery,html-table,Jquery,Html Table,我开发了一个表,在加载时使用PHP和mysql动态生成它的行。现在,我真正想要的是在单击按钮后使用Jquery仅刷新tbody元素。我已经写了在首都的评论,我想这样做。这是按钮的代码: $('#confirm').click(function() { var application = $('#discSwList').val(); $.ajax(
$('#confirm').click(function() {
var application = $('#discSwList').val();
$.ajax({
type:'POST',
url:'utility.php',
data: { unlockFlag: 1, appName: application, arrayCompSw: JSON.stringify(containerList)},
success : function() {
alert('Everything is fine');
// IN THE FOLLOWING STATEMENT I WOULD LIKE TO RELOAD ONLY THE tbody called "compSwDiscoveredList"
$('#compSwDiscoveredList').load('') ?????
},
error: function(err) {
alert(err);
}
});
});
});
html表格:
<table id="tableCompSwDiscoveredList" cellspacing="4" cellpadding="4">
<thead>
<th>Disassocia</th>
<th>ID SW CONFIG</th>
<th>ID SOFTWARE</th>
<th>SO</th>
<th>ID CONFIG</th>
<th>NOME APPARATO</th>
<th>IP ADDRESS</th>
</thead>
<tbody id="compSwDiscoveredList">
</tbody>
</table>
</div>
解离
ID软件配置
ID软件
所以
ID配置
诺姆公寓
IP地址
这将调用生成动态内容并将其插入div的PHP文件
希望这有帮助。要从json填充html内容,可以使用jquery模板库。我已经用jquery模板代码更改了您的函数
$('#confirm').click(function() {
var application = $('#discSwList').val();
$.ajax({
type:'POST',
url:'utility.php',
data: { unlockFlag: 1, appName: application, arrayCompSw: JSON.stringify(containerList)},
success : function(jsonData) {
alert('Everything is fine');
// Below "compSwDiscoveredList"
$("#tableTemplate").tmpl(jsonData).appendTo("#tableCompSwDiscoveredList");
},
error: function(err) {
alert(err);
}
});
});
});
var jsonData=[
{Disassocia:“Disassocia1”,IdSwConfig:“IdSwConfig 1”,IdSoftware:“IdSoftware1”,So:'So1',IdConfig:'IdConfig1',NomeApparato:'Nome Apparato1',IpAddress:'Ip Address1'},
{Disassocia:“Disassocia2”,IdSwConfig:“IdSwConfig g2”,IdSoftware:“IdSoftware2”,So:'So2',IdConfig:'IdConfig2',NomeApparato:'Nome Apparato2',IpAddress:'Ip Address2',
{Disassocia:“Disassocia3”,IdSwConfig:“IdSwConfig 3”,IdSoftware:“IdSoftware3”,So:'So3',IdConfig:'IdConfig3',NomeApparato:'Nome Apparato3',IpAddress:'Ip Address3'},
{Disassocia:“Disassocia4”,IdSwConfig:“IdSwConfig 4”,IdSoftware:“IdSoftware4”,So:'So4',IdConfig:'IdConfig4',NomeApparato:'Nome Apparato4',IpAddress:'Ip Address4'}
];
$(“#tableTemplate”).tmpl(jsonData).appendTo(“#TableCompsDiscoveryList”)代码>
${Disassocia}
${IdSwConfig}
${IdSoftware}
${So}
${IdConfig}
${NomeApparato}
${IpAddress}
解离
ID软件配置
ID软件
所以
ID配置
诺姆公寓
IP地址
您有必要研究jQuery的.load
函数。我尝试执行类似$(“#compSwDiscoveredList”).load(window.href.location+“#compSwDiscoveredList”)的操作,但它会在tbody中重新加载整个页面:(为您的应用程序添加HTML。)table@snack_overflow立即添加。内容已加载ajax@EmilioAlfieri要从JSON数据填充表内容,您必须创建html或jquery模板。这里是您可以获取帮助的链接不…它不起作用,因为我在php页面中放置了一个标志,因此“if语句”中的内容将永远不会执行。无论如何,您可以检查我的sintax吗?$(“#compSwDiscoveredList”).load('asset_discSoftwList.php'+#compSwDiscoveredList+“>*”,function(){});@EmilioAlfieri-我已经更新了答案以包含您的代码,您的php文件后面需要一个空格
$('#confirm').click(function() {
var application = $('#discSwList').val();
$.ajax({
type:'POST',
url:'utility.php',
data: { unlockFlag: 1, appName: application, arrayCompSw: JSON.stringify(containerList)},
success : function(jsonData) {
alert('Everything is fine');
// Below "compSwDiscoveredList"
$("#tableTemplate").tmpl(jsonData).appendTo("#tableCompSwDiscoveredList");
},
error: function(err) {
alert(err);
}
});
});
});