API IndexedDB
Publicado por Jean (22 intervenciones) el 23/02/2021 11:50:42
Hola, tengo este código y no se porque falla, es una base de datos para llevar registros de libros, deberia poderse agregrar datos a la base y poner leer una lista de ellos pero me da errores que no se de donde vienen.
Gracias
Gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!doctype html>
<head>
<script>
function iniciar()
{
var boton=document.getElementById("grabar");
boton.addEventListener("click",agregarlibro, false);
}
indexedDB.open = function crear()
{
var request = indexedDB.open("valores");
request.onsuccess = function(e)
{
indexedDB.db = e.target.result;
}
request.onfailure = indexedDB.onerror;
}
function crear (e)
{
bd=e.result
if(bd.version=="");
{
var solicitud=bd.setVersion("1.0")
solicitud.addEventListener("error",errores, false);
solicitud.addEventListener("success",crearbd,false);
}
}
function agregarlibro( )
{
var indentificador = document.getElementById("identificador").value
var titulo=document.getElementById("titulo").value
var ano=document.getElementById("año").value
var transaccion=bd.transaction(["biblioteca"],IDBTransaction.Lista)
var almacen=transaccion.objectStore("titulo")
solicitud.addEventListener("Success",function(){mostrar(clave)},false);
document.getElementById("identificador").value=""
document.getElementById("titulo").value=""
document.getElementById("año").value=""
}
function mostrar(clave)
{
var transaccion=bd.transaction(["biblioteca"])
var almacen=transaccion.objectStore("titulo")
var solicitud=almacen.get(clave)
solicitud.addEventListener("success",mostrarlista, false)
}
function mostrarlista(e)
{
var resultado=e.result
cajadatos.innerHTML="<div>"+resultado.id+" - "+resultado.nombre+" - "+resultado.fecha+"<div>"
}
window.addEventListener("load", iniciar, false);
</script>
</head>
<body>
<section id="biblioteca">
<form name="formulario">
<p>Identificador del libro:<br><input type="text" name="idetificador" id="identificador"></p>
<p>Titulo:<br><textarea name="titulo" id="titulo"></textarea></p>
<p>Año de publicacion<br><textarea name="año" id="año"></textarea></br></p>
<p><input type="button" name="grabar" id="grabar" value="Grabar"></p>
</form>
</section>
<section id="cajadatos">
No hay informacion disponible
</section>
</body>
Valora esta pregunta


0