Commit 7bb59939 authored by Mat's avatar Mat

un bouton new pour vider le form

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