Change Request from a Scroll - Javascript

0

I need help, I have determined that I return 200 requests from json, with the help of the stackoverflow community to get handle as you know when the scroll reaches the end of the content, now I have a question to modify the request value when scroll to the end.

var getJSON = (url, callback) => {
    var http = new XMLHttpRequest();
    http.open('GET', url, true);
    http.responseType = 'json';
    http.onload = () => {
      var status = http.status;
      if (status === 200) {
        callback(null, http.response);
      } else {
        callback(status, http.response);
      }
    };
    http.send();
};

var mostrado;

window.onload = function table() {
    var container   = document.getElementById("container");
    var table       = document.getElementById("table");
    container.appendChild(table);
    var tr1         = document.createElement("tr");
    tr1.setAttribute("id", "trData");
    table.appendChild(tr1);
    var th1         = document.createElement("th");
    th1.setAttribute("id", "thData");
    var th2         = document.createElement("th");
    th2.setAttribute("id", "thDataName");
    var th3         = document.createElement("th");
    th3.setAttribute("id", "thDataUid");
    tr1.appendChild(th1);
    tr1.appendChild(th2);
    tr1.appendChild(th3);
    var Theader     = document.createTextNode("Nª:");
    th1.appendChild(Theader);
    var Theader     = document.createTextNode("Uid:");
    th2.appendChild(Theader);
    var Theader     = document.createTextNode("Company:");
    th3.appendChild(Theader);
    mostrado = 200;
    document.querySelector("#table").addEventListener('scroll', function() { // Função para mostrar quando o scroll chega no final
        if (Math.ceil(this.scrollTop) + this.offsetHeight == this.scrollHeight) {
            mostrado += 200;
            console.log("final do scroll" + mostrado);
        } 
    });
    getJSON('dados.json', (err, data) => { // Retornando Dados do JSON
        if(err !== null) {
            console.log(err + "teste")
        } else {
            console.log(mostrado);
            for (var i=0; i < mostrado ; i++) { // "Mostrado" = 200 , Retornando 200 valores do JSON
                var tr2  = document.createElement("tr");
                tr2.setAttribute("id", "trData1");
                table.appendChild(tr2);  
                var td1  = document.createElement("td");
                td1.setAttribute("id", "tdData");
                var td2  = document.createElement("td");
                td2.setAttribute("id", "tdData");
                var td3  = document.createElement("td");
                td3.setAttribute("id", "tdData");
                tr2.appendChild(td1);
                tr2.appendChild(td2);
                tr2.appendChild(td3);
                var Theader1 = document.createTextNode(i);
                td1.appendChild(Theader1);
                var Theader1 = document.createTextNode(data[i]._id);
                td2.appendChild(Theader1);
                var Theader1 = document.createTextNode(data[i].company);
                td3.appendChild(Theader1);
            }
        }
    }) 

}
    
asked by anonymous 06.07.2018 / 19:01

0 answers