Commit 7bb59939 authored by Mat's avatar Mat

un bouton new pour vider le form

parent d206c098
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<body> <body>
<ul id="brasserie"></ul> <ul id="brasserie"></ul>
<button id="new">New</button>
<form id="form"> <form id="form">
Nom <input type="text" name="nom"><br> Nom <input type="text" name="nom"><br>
Adresse <input type="text" name="adresse"><br> Adresse <input type="text" name="adresse"><br>
...@@ -19,6 +20,11 @@ ...@@ -19,6 +20,11 @@
$(document).ready(function() $(document).ready(function()
{ {
let targetedId; let targetedId;
$('#new').click(function(e) {
e.preventDefault();
targetedId = undefined;
$('input').val('');
});
$.ajax({ $.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie", url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie",
dataType: 'JSON', dataType: 'JSON',
...@@ -54,40 +60,23 @@ $(document).ready(function() ...@@ -54,40 +60,23 @@ $(document).ready(function()
$('#send').click(function(e) $('#send').click(function(e)
{ {
e.preventDefault(); e.preventDefault();
if (typeof targetedId === 'undefined') { $.ajax({
$.ajax({ url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie" + (targetedId !== undefined ? '/' + targetedId : ''),
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie", dataType: 'JSON',
dataType: 'JSON', method: (targetedId !== undefined ? 'PUT' : 'POST'),
method: 'POST', data: $('#form').serialize(),
data: $('#form').serialize(), success: function(data) {
success: function(data) { alert('success');
alert('success'); },
}, error: function(xhr) {
error: function(xhr) { console.log(xhr);
console.log(xhr); alert('error');
alert('error'); }
}
});
} else {
$.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie/" + targetedId,
dataType: 'JSON',
method: 'PUT',
data: $('#form').serialize(),
success: function(data) {
alert('success');
},
error: function(xhr) {
console.log(xhr);
alert('error');
}
}); });
}
}); });
}); });
</script> </script>
</html>
</body> </body>
</html>
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