HTML Таблица не отображается в модальном - PullRequest
0 голосов
/ 29 февраля 2020

То, что я пытаюсь сделать, это получить некоторые данные от стороннего API и вывести результаты в модальном режиме для выбора. Но таблица не обрабатывается

Это Bootstrap HTML для модального ...

в таблице есть временная таблица, чтобы увидеть, не было ли это фактом что я неправильно заполнил.

<div class="modal" id="companiesModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-body">
            <div class="panel panel-default">
                <div class="panel-body">
                    <table class="table table-hover" id="companies">
                        <thead>
                            <tr>
                                <th scope="col">Company Number</th>
                                <th scope="col">Company Name</th>
                            </tr>
                        </thead>

                        <tbody>
                            <tr>
                                <td scope="col">Company Number</td>
                                <td scope="col">Company Name</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="closeModal()">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
        </div>
    </div>
</div>

Эта функция вызывается при нажатии кнопки в форме ..

function companiesHouseSearch() {
        if ($("input#companyName").val() == "") {
            alert("Please enter a company name to get started...");
            return;
        }

        $.ajax({
            dataType: 'json',
            url: '/Home/GetCompaniesHouseEntries',
            type: 'GET',
            data: { companyName: $("input#companyName").val() },
            success: function (data, status) {
                $("#companies").empty()

                var rows = "";
                $.each(data, function(){
                    rows += "<tr><td>" + this.company_number + "</td><td>" + this.company_name + "</td></tr>";
                });

                $(rows).appendTo("#companies tbody");

                $("#companiesModal").show();
            },
            failure: function () { alert('failure') },
            error: function (request, error) { alert(error)}
        });

    };
...