Laravel/Ajax:在 ajax 函数中使用 class/id 来调用 table 内容而不是标签

Laravel/Ajax: use a class/id in an ajax function to call table content instead of tag

首先,这是我的 UI:

由于在我的 ajax:

中使用了标签 <tbody>,我的右侧显示了我的输出
success: function (response){
    var tbody="";
    $.each(response.all_categories, function (key, cat) {
    tbody+=`
    <tr>
        <td class="p-0 btn-category-list-col">
          <button id="submit" type="submit" class="btn float-left" data-toggle="modal" data-target="#createCategory">${cat.category_name}</button>
        </td>
    </tr>`; });

    $('tbody').html(tbody) }

我的问题是我在同一个页面中使用了两个 <tbody>,所以右边的 table 出现在左边:

有没有办法让我的 ajax 函数读取 class 或 id 而不是标签本身?:

有点像我的台词 tbody+= 变成了:tbody(class/id)+=

这是我的 table,它使用了两个 tbody 标签:

    <div class="col-md-2 border">
        <table id="categoryList" class="table">
            <thead>
                <tr>
                    <th class="thead-category-list">Category List</th>                
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>

            <div class="col-md-10 border bbr-table-col">

                <div id="success_message"></div>
                <table id="categoryList" class="table table-striped table-bordered responsive no-wrap" cellspacing="0" width="100%">
                    <thead>
                        <tr class="bbr-table text-light">
                            <th>Group Name</th>                
                            <th>Group Type</th>
                            <th>Group Users</th>
                            <th>Status</th>
                            <th>Active</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
    </div>

任何帮助将不胜感激谢谢

如果您没有为两个 table 使用相同的 ID(顺便说一句,这是无效的 html),您可以将 table ID 用于 select 正确的。
从上面的 html 你可以使用 table class 来识别它

$('table.table-striped tbody').html(tbody);

或者您可以修复无效的重复 ID,并使用该 ID select 正确的 table

<div class="col-md-2 border">
    <table id="side-categoryList" class="table">
        <thead>
            <tr>
                <th class="thead-category-list">Category List</th>                
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>

        <div class="col-md-10 border bbr-table-col">

            <div id="success_message"></div>
            <table id="main-categoryList" class="table table-striped table-bordered responsive no-wrap" cellspacing="0" width="100%">
                <thead>
                    <tr class="bbr-table text-light">
                        <th>Group Name</th>                
                        <th>Group Type</th>
                        <th>Group Users</th>
                        <th>Status</th>
                        <th>Active</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
</div>
$('#main-categoryList tbody').html(tbody);