Невозможно создать HTML-таблицу с динамическим заголовком и строками - PullRequest
0 голосов
/ 21 мая 2019

Я пытаюсь создать таблицу HTML с помощью Jquery. Оба заголовка и строки таблицы происходят из 2 разных API. Для строк Body: 1 WebAPI, обслуживающий данные непосредственно в виде JSON, а для заголовка другой API хранит значение в текстовом файле в папке веб-сервера, где я храню свой HTML-файл. Мой Jquery может получать массив из WEBAPI, а также создавать текстовый файл из 2-го API. Но почему-то я не могу прочитать сохраненный текстовый файл. Кидает ниже ошибки -

logapifull.php?query=day_t&&val=dareo
test.html?query=day_t&&val=dareo:208 {data: Array(100)}
test.html?query=day_t&&val=dareo:224 logapiheader.php?query=day_t&&val=dareo
jquery.min.js:2 **GET http://localhost:8000/log_check/test.txt 404 (Not Found)**

Вот моя часть HTML -

<div style="padding-top:5px; width:65%; padding-left:2%">
                <table id="q4" class="table table-bordered table-hover table-striped" style="width:100%">

        </table>
        </div>

А вот и мой JQuery -

var lastFormat = 0;
var tabl = getUrlVars()["query"];
var owner = getUrlVars()["val"];
document.getElementById("header").innerText = 'Table ' + owner + '.' + tabl;
var qur = 'logapifull.php?query='+ tabl +'&&val='+ owner +'';
console.log(qur);
$(document).ready(function () {
    $.ajax({
        type: "POST",
        url: qur,
        datatype: "JSON",
        success: function (response) {
            var data = response;
            console.log(data);
            createTable(lastFormat, data);
            }       
    });
});

function transpose() {
    if (lastFormat === 0) {
        createTable(1);
    } else {
        createTable(0);
    }
}

function createTable(format, data) {
var head = 'logapiheader.php?query='+ tabl +'&&val='+ owner +'';
console.log(head);
$(document).ready(function () {
    $.ajax({
        type: "POST",
        url: head,
        datatype: "JSON",
        success: function (response) {
            //var data = response;
            //console.log(data);
            createTable(lastFormat, data);
            }       
    });
});
    var rows = data.data;
    var table = document.getElementById('q4');
    $.get('test.txt', function(data) {
    var heading = data;
    console.log(heading);

    if (format === 0) {
        var thead = "<thead><tr>";
        for (i = 0; i < heading.length; i++) {
            thead += "<th>" + heading[i] + "</th>"
            console.log(heading.length);
        }
        thead += "</tr></thead>";
        var tbody = "<tbody>";

        for (j = 0; j < rows.length; j++) {
            tbody += "<tr>"
            for (k = 0; k < rows[j].length; k++) {
                tbody += "<td>" + rows[j][k] + "</td>"
            }
            tbody += "</tr>"
        }
        tbody += "</tbody>"

        table.innerHTML = thead + tbody;

    } else if (format === 1) {
        var tbody = "<tbody>";
        for (i = 0; i < heading.length; i++) {
            tbody += "<tr>"
            tbody += "<th>" + heading[i] + "</th>"
            for (j = 0; j < rows.length; j++) {
                tbody += "<td>" + rows[j][i] + "</td>"
            }
            tbody += "</tr>"
        }
        tbody += "</tbody>"
        table.innerHTML = tbody;

    }
    }, 'text');
}

Вот веб-ответ текстового файла -

Webresponse of text file

Вот фактический текстовый файл -

enter image description here

Может кто-нибудь, пожалуйста, сообщите мне, как прочитать упомянутый файл или что я здесь не так делаю?

...