Compare commits
8 Commits
4f64cb71eb
...
1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| ba1a68a255 | |||
| 5702600095 | |||
| 306dd41e3b | |||
| c4475a1458 | |||
| 85afdbdbbe | |||
| 5dec469c24 | |||
| f38f06bef6 | |||
| a28fdb198b |
@@ -1,3 +1,5 @@
|
|||||||
|
Applicazione web per interfacciarsi a PizzaExpress, disponibile per il download su [questo repository](https://git.fiorencis.eu/SmerdoRepository/PizzaExpress)
|
||||||
|
|
||||||
## Informazioni su CORS
|
## Informazioni su CORS
|
||||||
Per svariati motivi il web frontend potrebbe non riuscire ad effettuare richieste API ad altri endpoint per direttive CORS.
|
Per svariati motivi il web frontend potrebbe non riuscire ad effettuare richieste API ad altri endpoint per direttive CORS.
|
||||||
In caso di errori CORS assicurarsi che:
|
In caso di errori CORS assicurarsi che:
|
||||||
|
|||||||
20
add.html
Normal file
20
add.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="it">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Aggiungi pizza</title>
|
||||||
|
<script src="script.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form id="addForm" onsubmit="handleAddPizza(event)" >
|
||||||
|
<label for="id">ID Pizza</label><br>
|
||||||
|
<input type="number" id="id" name="id" required><br>
|
||||||
|
<label for="name">Nome</label><br>
|
||||||
|
<input type="text" id="name" name="name" required><br>
|
||||||
|
<label for="prezzo">Prezzo</label><br>
|
||||||
|
<input type="number" step="0.01" id="price" name="price" required><br><br>
|
||||||
|
<input type="submit" value="Aggiungi">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
12
index.html
12
index.html
@@ -12,10 +12,14 @@
|
|||||||
<h1>PizzaExpress</h1>
|
<h1>PizzaExpress</h1>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<button onclick="location.href='add.html'">+</button>
|
<div class="pageControls">
|
||||||
<button onclick="listPizze()">Aggiorna</button>
|
<div>
|
||||||
<br><br>
|
<button onclick="window.open('add.html', 'popup', 'width=400,height=300')">+</button>
|
||||||
<div id="tabellaPizze"></div>
|
<button onclick="listPizze()">Aggiorna</button>
|
||||||
|
<br><br>
|
||||||
|
</div>
|
||||||
|
<div id="tabellaPizze"></div>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
18
script.js
18
script.js
@@ -84,7 +84,7 @@ function editPizza(id){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPizza(nome, id, prezzo){
|
function addPizza(id, nome, prezzo){
|
||||||
const myHeaders = new Headers();
|
const myHeaders = new Headers();
|
||||||
myHeaders.append("Content-Type", "application/json");
|
myHeaders.append("Content-Type", "application/json");
|
||||||
|
|
||||||
@@ -101,14 +101,24 @@ function addPizza(nome, id, prezzo){
|
|||||||
redirect: "follow"
|
redirect: "follow"
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(apiUrl + "/api/pizze/" + id, requestOptions)
|
fetch(apiUrl + "/api/pizze", requestOptions)
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
alert("Pizza aggiunta con successo!");
|
alert("Pizza aggiunta con successo! Aggiorna la lista per mostrarla in pagina.");
|
||||||
listPizze();
|
window.close();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
alert("Errore nell'aggiunta, controllare la console per dettagli sull'errore.");
|
alert("Errore nell'aggiunta, controllare la console per dettagli sull'errore.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleAddPizza(event){
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const nome = document.getElementById("name").value;
|
||||||
|
const id = document.getElementById("id").value;
|
||||||
|
const prezzo = document.getElementById("price").value;
|
||||||
|
|
||||||
|
addPizza(id, nome, prezzo);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user