Commit af294600 authored by Mat's avatar Mat

ajax, externalise la fonction postAJAX

parent f50cf34a
......@@ -136,19 +136,17 @@
form.addEventListener('submit', function(e) {
let createURL = '{{ path('api_owner_create') }}';
let form = this;
// Annule l'événement, mais préserve la fonction callback
e.preventDefault();
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
postAJAX(createURL, function() {
if (this.readyState === 4 && this.status === 200) {
reloadTableOwner();
}
};
xhr.open('POST', '{{ path('api_owner_create') }}', true);
xhr.send(new FormData(form));
}, form);
});
......
......@@ -16,6 +16,14 @@ function getAJAX(url, callback)
xhr.send(null);
}
function postAJAX(url, callback, post)
{
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = callback;
xhr.open('POST', url, true);
xhr.send(new FormData(post));
}
/* // pour info
function getAJAX_v2(url, callback)
{
......@@ -32,7 +40,3 @@ function getAJAX(url, callback)
xhr.send(null);
}
*/
function postAJAX()
{
}
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