This commit is contained in:
paoloar77
2024-05-20 23:38:06 +02:00
parent 764f906d2b
commit 0247b93466

View File

@@ -8,30 +8,29 @@
<body> <body>
<h1>Links</h1> <h1>Links</h1>
<form id="articleForm"> <form id="articleForm">
<label for="article_id">Inserisci l'ID dell'articolo:</label> <label for="article_id">ID Articolo:</label>
<input type="text" id="article_id" name="id" /> <input type="text" id="article_id" name="id" />
<select name="action"> <button type="button" data-action="search">Cerca Articolo</button>
<option value="search">Cerca Articolo</option> <button type="button" data-action="checkPreOrder">Verifica Preordine</button>
<option value="checkPreOrder">Verifica Preordine</option>
</select>
<button type="submit">Esegui Azione</button>
</form> </form>
<div id="result"></div> <div id="result"></div>
<script> <script>
document.getElementById('articleForm').addEventListener('submit', function(event) { const form = document.getElementById('articleForm');
event.preventDefault(); const result = document.getElementById('result');
let formData = new FormData(this); const buttons = form.querySelectorAll('button');
let id = formData.get('id'); buttons.forEach(button => button.addEventListener('click', handleButtonClick));
let action = formData.get('action');
fetch('{{ url('handle-article-action-pao') }}/' + id + '/' + action) function handleButtonClick(event) {
.then(response => response.text()) const action = event.target.dataset.action;
.then(data => { const id = form.querySelector('input[name="id"]').value;
document.getElementById('result').innerHTML = data;
}); fetch(`${window.location.origin}/handle-article-action-pao/${id}/${action}`)
}); .then(response => response.text())
.then(data => result.innerHTML = data);
}
</script> </script>
</body> </body>
</html> </html>