Sincronía vs Asincronía
https://<nombre-del-proyecto>.firebaseio.com/<nombre-de-la-coleccion>.json
Coloque identificadores únicos al formulrio y a los elementos del formulario, p.e.:
<form id="formulario" ... >
...
<input id="form_name" type="text" ... >
...
<select id="form_products"> ... </select>
...
</form>
Detenga el comportamiento predeterminado del formulario al evento submit, p.e.:
...
myform.addEventListener('submit', (eventSubmit) => {
eventSubmit.preventDefault()
...
})
...
Verifique la existencia de contenido válido en los elementos del formulario.
...
myform.addEventListener('submit', (eventSubmit) => {
eventSubmit.preventDefault()
if (form_name.value.length == 0) {
alert("Nombre requerido")
form_name.focus()
return;
}
...
})
...
asíncrono
HTTP - POST
, de los datos de un formulario, mediante fetch
.For comparison here is how synchronous data fetching would work. pic.twitter.com/GTjqmpnz3K
— Yash (@yashguptaz) March 8, 2020
Asynchronous JavaScript Promises Visualized.
— Yash (@yashguptaz) March 8, 2020
Notice how Web APIs are given the task of processing the request and the output is received back by the main thread.
This shows how single-threaded JavaScript can do async operations.
Animation made by me. pic.twitter.com/p5vprPyxzn
fetch, sincronía, asíncrona, firebase, json, xml, HTTP - GET