简体   繁体   English

使用AJAX更新多个HTML表行

[英]Update multiple HTML table rows using AJAX

I have a table that shows information pulled from a PHP script like so: 我有一张表,显示从PHP脚本提取的信息,如下所示:

<tr class="online" id="0011e31xxxxx">
  <td><input type="checkbox" name="mac" value="0011e31xxxxx"></td>
  <td>1234567</td>
  <td>Modelnumber</td>
  <td>0011.e31x.xxxx</td>
  <td>10.x.x.x</td>
  <td>UBR4</td>
  <td>online</td>
  <td><a href="javascript:void(0);" onclick="getInfo('0011e31xxxxx','10.x.x.x','UBR4','resetubr');"><img src="/own/v2.2/images/reset.gif"></a></td>
  <td><a href="javascript:void(0);" onclick="getInfo('0011e31xxxxx','10.x.x.x','UBR4','resetsnmp');"><img src="/own/v2.2/images/reset.gif"></a></td>
  <td><a href="javascript:void(0);" onclick="getInfo('0011e31xxxxx','10.x.x.x','UBR4','refresh');"><img src="/own/v2.2/images/icone_refresh.png"></a></td>
</tr>

The 3 getInfo calls links are as follow and work perfectly: 3个getInfo调用链接如下,它们可以正常工作:

<script>
function getInfo(id,adresseip,ubr,action) {
        var rowid = "tr#" + id;
        $.ajax({
            type: "GET",
            cache: false,
            url: 'index.php',
            data: "macaddress=" + id + "&ubr=" + ubr + "&adresseip=" + adresseip + "&action=" + action,
            beforeSend: function() {
                $(rowid).addClass("loading");
            },
            success: function(data) {
                $(rowid).replaceWith(data);
            }
        });
}
</script>

What I am trying to do is use the checkbox available at the beginning of each <tr> in order to generate some kind of loop to run one of the three links seen on each row. 我想做的是使用每个<tr>开头的复选框,以生成某种循环来运行每一行上看到的三个链接之一。

Lets say I check 3 boxes (value 123, 234 and 345), I need the <tr id=123><tr id=234> and <tr id=345> to update their respective lines only while the rest of the data remains intact. 假设我选中了3个框(值123、234和345),我需要<tr id=123><tr id=234> and <tr id=345>仅在其余数据保留时更新它们各自的行完整。

Is it possible to make such a loop to call the AJAX function to be run as many times as there are selected checkboxes? 是否可以进行这样的循环以调用AJAX函数,使其运行与选定复选框一样多的次数? Or can the AJAX function iterate over each selected checkbox in order to update them one after the other? 或者,AJAX函数可以遍历每个选中的复选框,以便一个接一个地更新它们吗?

Thank you 谢谢

Please Search on google then try... if you don't get any answer then raise the Question... 请在Google上搜索,然后尝试...如果您没有得到任何答案,请提出问题...

Check this Link.. 检查此链接。

$('#TableID > tr').each(function() {
    var postData = {
    'FirstName':$(this).find('#FirstName').val(),
    'SurName':$(this).find('#Surname').val()
    };
    $.ajax({
    type: "POST",
    cache: false, 
    url: "WuFoo.aspx",
    data: postData ,
    success: success
    });
 });

You can get all checked check boxes with JQuery by doing something like 您可以通过执行以下操作来使用JQuery选中所有选中的复选框

$("input[type=checkbox]:checked")

You can then use .each to iterate over them and update each appropriate row. 然后,您可以使用.each遍历它们并更新每个适当的行。

That code should go in your success: function of your ajax call. 该代码应该可以success: ajax调用的功能。

Alternately you can use that same JQuery code to get the checked boxes, and then selected the <tr> in the .each and use that data to make an Ajax call. 或者,您可以使用相同的JQuery代码来获取复选框,然后在.each选择<tr>并使用该数据进行Ajax调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM