Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 22, 2018 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/d83e57022949538026ab83061ac48714 to your computer and use it in GitHub Desktop.
Save parzibyte/d83e57022949538026ab83061ac48714 to your computer and use it in GitHub Desktop.
Paso 2: insertar datos con PouchDB
<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.jsdelivr.net/npm/pouchdb@6.4.1/dist/pouchdb.min.js"></script>
</head>
<body>
<h1>Agenda con PouchDB</h1>
<a target="_blank" href="https://www.parzibyte.me/blog">https://www.parzibyte.me/blog</a>
<br />
<label for="nombreCompleto">Nombre:</label>
<br>
<input placeholder="Nombre y apellidos" type="text" name="nombreCompleto" id="nombreCompleto" />
<br>
<br>
<label for="direccion">Dirección:</label>
<br>
<textarea placeholder="Escribe la dirección..." name="direccion" id=direccion rows="4" cols="30"></textarea>
<br>
<br>
<label for="telefono">Teléfono:</label>
<br>
<input placeholder="Por ejemplo, 555 222 333" type="tel" name="telefono" id="telefono" />
<br>
<br>
<button id="btnGuardar">Guardar</button>
<script src="script.js"></script>
</body>
</html>
var bd = new PouchDB("agenda"),
$nombreCompleto = document.querySelector("#nombreCompleto"),
$direccion = document.querySelector("#direccion"),
$telefono = document.querySelector("#telefono"),
$btnGuardar = document.querySelector("#btnGuardar");
$btnGuardar.addEventListener("click", function() {
var nombreCompleto = $nombreCompleto.value,
direccion = $direccion.value,
telefono = $telefono.value;
if (nombreCompleto && direccion && telefono) {
bd.post({
nombre: nombreCompleto,
direccion: direccion,
telefono: telefono
})
.then(function(respuesta) {
if (respuesta.ok) {
alert("Guardado correctamente");
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment