Advertisement
Grossos

ranking.js

Sep 6th, 2023 (edited)
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener('DOMContentLoaded', () => {
  2.    fetch('http://127.0.0.1:5000/getAll') // , headers
  3.    .then(response => response.json())
  4.    .then(data =>  loadHTMLTable(data['data']));
  5.    
  6. });
  7.  
  8. const addBtn = document.querySelector('#add-name-btn');
  9.  
  10. addBtn.onclick = () => {
  11.     const nameInput = document.querySelector('#name-input');
  12.     const name = nameInput.value;
  13.     nameInput.value = '';
  14.  
  15.     fetch('http://127.0.0.1:5000/insert', {
  16.         headers: {
  17.             'Content-type': 'application/json'
  18.         },
  19.         method: 'POST',
  20.         body: JSON.stringify({ name : name })
  21.     })
  22.     .then(response => response.json())
  23.     .then(data => insertRowIntoTable(data['data']));
  24.    
  25. }
  26.  
  27. function insertRowIntoTable(data) {
  28.  
  29. }
  30.  
  31. function loadHTMLTable(data) {
  32.     const table = document.querySelector('table tbody');
  33.  
  34.    // console.log(data);
  35.    
  36.     if (data.length === 0) {
  37.         table.innerHTML = '<tr><td class="no-data" colspan="5">No Data</td></tr>';
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement