Commit b4fdb2b2 authored by Mat's avatar Mat

la fonction ajax, commentée et finalisée

parent 515e5ae4
......@@ -18,18 +18,24 @@
{% block customJS %}
<script type="text/javascript">
// L'URL de l'API
let ownersURL = '{{ path('api_owner_read') }}';
// Le tableau
let table = document.querySelector("table#table-owners");
let tbody = table.querySelector("tbody");
console.log(ownersURL);
console.log(table);
//console.log(ownersURL);
//console.log(table);
// La fonction AJAX
function reloadTableOwner()
{
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
console.log(this);
//console.log(this);
if (this.readyState === 4
&& (this.status === 200 || this.status === 0)) {
......@@ -38,26 +44,37 @@
for (let i = 0; i < json.length; i++)
{
let tr = document.createElement('tr');
let td1 = document.createElement('td');
td1.textContent = json[i].firstname;
tr.appendChild(td1);
let td2 = document.createElement('td');
td2.textContent = json[i].lastname;
tr.appendChild(td2);
let td3 = document.createElement('td');
td3.textContent = json[i].created_at;
tr.appendChild(td3);
let td4 = document.createElement('td');
td4.textContent = json[i].modify_at;
td4.innerHTML =
'<a class="btn btn-primary" href="#"><i class="fas fa-edit fa-fw"></i> Editer</a>'
+ '<a class="btn btn-danger" href="#"><i class="fas fa-trash fa-fw"></i> Supprimer</a>';
tr.appendChild(td4);
tbody.appendChild(tr);
console.log(json[i].firstname);
}
console.log(json);
}
};
xhr.open('GET', ownersURL, true); // les données GET sont dans ownersURL
xhr.send(null); // les données POST seraient ici
}
// dans la console JS, recharger la fonction suivante pour voir apparaitre le debug Ajax de Symfony
reloadTableOwner();
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment