Skip to content

Commit

Permalink
Añadimos el fetch para crear POST en el servidor
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarlpb committed Jul 7, 2023
1 parent 85e9474 commit 0cc822b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion examen-3-cen/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ function App() {
}
const handleSubmit = (e) => {
e.preventDefault(); // Evita que se recargue la página
// fetch() para enviar los datos a un endpoint

// Envía los datos al servidor
const url = "http://localhost:3000/posts";
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
'Access-Control-Allow-Origin': '*'
},
body: JSON.stringify({title, content, tags})
})
.then(res => res.json())
.then(data => console.log(data));

resetearCampos();
alert("Datos enviados");
}
Expand Down

0 comments on commit 0cc822b

Please sign in to comment.