const endPoint ="http://jailton.bootcamp.dev.netuno.org:20190/services";
|
|
|
|
document.querySelector('#btnSub').addEventListener('click', e => {
|
|
e.preventDefault();
|
|
|
|
const nome = document.querySelector('#inputNome').value;
|
|
const estado = document.querySelector('#inputEstado').value;
|
|
const area = document.querySelector('#inputArea').value;
|
|
|
|
const park = {nome:nome,estado:estado,area:Number(area)};
|
|
|
|
newParque(park);
|
|
|
|
})
|
|
|
|
async function newParque(park) {
|
|
|
|
const config = {
|
|
method:'POST',
|
|
body:JSON.stringify(park),
|
|
headers: {
|
|
"Content-type":"application/json",
|
|
}
|
|
}
|
|
|
|
try {
|
|
await fetch(`${endPoint}/parque`,config).then((res)=>res.json()).catch((err)=>err);
|
|
alert("Parque cadastrado com sucesso!");
|
|
} catch (error) {
|
|
alert("Erro ao cadastrar parke, erro: "+error.message);
|
|
}
|
|
|
|
}
|