var tr = ''; document.getElementById('form').addEventListener('submit', function(e) { e.preventDefault(); // try { // while (document.getElementsByName('tr')) { // document.getElementsByName('tr')[0].remove(); // } // } catch (e) { // // } let data = new FormData(this); console.log(data); let xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (this.response != false) { this.response.forEach((item, i) => { console.log(push_line(item[0])); console.log('salut' + tr); document.getElementsByTagName('tbody')[0].innerHTML = tr; let ticket = document.getElementsByClassName("'" + item[0] + "'"); console.log(ticket); for (let i=0; i < 11; i++) { ticket[i].textContent = item[i]; } if (item[11] == 1) { ticket[11].querySelector('img').src = "../img/check.png"; } else { ticket[11].querySelector('img').src = "../img/excla.png"; } document.getElementsByTagName('table')[0].style.display = 'block'; }); } else { alert("Ce ticket n'existe pas"); } } else if (this.readyState == 4) { alert('uhe erreur est survenue...'); } }; xhr.open('POST', 'cible/search.php', true); xhr.responseType = 'json'; xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.send("champ=" + encodeURI(data.get('champ')) + "&" + "value=" + encodeURI(data.get('value'))); }); function push_line(clas) { let xhr = new XMLHttpRequest(); xhr.open('POST', 'include/line.php', true); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { tr = this.response; console.log(tr); return tr; } } xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.send("class=" + encodeURI(clas)); }