Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有ajax刷新的Tablesorter不能与多个_Javascript_Jquery_Ajax_Jquery Ui - Fatal编程技术网

Javascript 带有ajax刷新的Tablesorter不能与多个

Javascript 带有ajax刷新的Tablesorter不能与多个,javascript,jquery,ajax,jquery-ui,Javascript,Jquery,Ajax,Jquery Ui,我正在使用jQueryUI选项卡,每个页面上都有一个表。这些表是按顺序排列的 当我在一个页面上刷新一个表时,下面的代码非常有用。如果添加第二个带有刷新的表,则只有第一个表会更新。有人能告诉我如何使用ajax刷新数据,通过tablesorter对两个表进行排序吗 重新加载通过以下JS函数运行: $(function () { $(".tsRefresh").tablesorter({ headers: { '.cbsort': { sorter: 'checkbox

我正在使用jQueryUI选项卡,每个页面上都有一个表。这些表是按顺序排列的

当我在一个页面上刷新一个表时,下面的代码非常有用。如果添加第二个带有刷新的表,则只有第一个表会更新。有人能告诉我如何使用ajax刷新数据,通过tablesorter对两个表进行排序吗

重新加载通过以下JS函数运行:

$(function () {

   $(".tsRefresh").tablesorter({
    headers: {
        '.cbsort': { sorter: 'checkbox' },
        '.nosort': { sorter: false, parser: false }
    },
    theme : 'jui',
    headerTemplate : '{content} {icon}', 
    widgets : ['saveSort', 'uitheme'],
    widgetOptions : {
        zebra   : ["odd", "even"]
    }
});

function getBjson() {

    var Tid = $('.tsRefresh').data('id');
    var Ttable = $('.tsRefresh').data('table');
    var Tbody = $('.tsRefresh').find('tbody').attr('id')
     $.ajax({
        type: "POST",
        url: "ajax.php",
        data: 'table=' + Ttable +'&id=' + Tid,
        success: function(output) {
             document.getElementById(Tbody).innerHTML = output;
             // update tablesorter cache
             $(".tsRefresh").trigger("update");         
        },
        error: function (xhr, ajaxOptions, thrownError) {
            $('#messageResponse').fadeIn(500);
            $('#messageResponse').addClass('ui-state-error ui-corner-all').removeClass('ui-highlight-error');
            $('#messageResponse').text(xhr.status + ' ' + thrownError + ': Something went wrong - check your inputs and try again.');
        }
    });

}

if( $('.tsRefresh').length) {
    var Ttime = $('.tsRefresh').data('time');
    var timer = setInterval(getBjson, Ttime);
    getBjson();
}

});
下表代码如下:

<div id="tabs-1">
    <fieldset>
    <table width="100%" id="issue" name="issue" class="tsRefresh" data-id="<?=$item_id?>" data-table="eq-load" data-time="10000">
        <thead>
            <tr class="bold">
                <th class="cbsort"><input type="checkbox" class="checkall"> </th>
                <th>OAN/ID</th>
                <th>Category</th>
                <th>Desc</th>
                <th>Issued To</th>
                <th>SN</th>
            </tr>
        </thead>
        <tbody id="container1">         
        </tbody>
    </table>                        
    </fieldset>
</div>          
<div id="tabs-2">
    <fieldset>
    <table width="100%" id="my-load" name="my-load" class="tsRefresh" data-id="<?=$item_id?>" data-table="eq-load-me" data-time="10000">
        <thead>
            <tr class="bold">
                <th class="cbsort"><input type="checkbox" class="checkall"> </th>
                <th>OAN/ID</th>
                <th>Category</th>
                <th>Desc</th>
                <th>Issued To</th>
                <th>SN</th>
            </tr>
        </thead>
        <tbody id="container2">
        </tbody>
    </table>                        
    </fieldset>
</div>


你必须在某处设置一个循环<代码>$('.tsRefresh')
将返回要循环的表。我不确定要循环什么。PHP脚本中的所有内容都是通过while循环生成的(除了数据本身之外,两个表的输出是相同的)。我不能在一个页面上多次调用这个JS函数吗?没有PHP需要更改,只有JS。重新排列代码,以便每个表(通过循环)调用
getBjson()
,而不仅仅是第一个表。
<tr class="dialog-hover" data-table="eq-load-item" data-id="<?=$item_id?>">
    <td align="center"><input type="checkbox" id="row-<?=$item_id?>" value="<?=$item_id?>"></td>
    <td align="center" valign="top"><a href="eq.view.php?id=<?=$item_id?>"><?=$item_oan?>-<?=$item_id?></a></td>
    <td><?=$item_cat?></td>
    <td align="center" valign="top"><?=$item_desc?></td>
    <td align="center" valign="top"><?=$issue_name?></td>
    <td align="center" valign="top"><?=$item_serial?></td>
</tr>