Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/06/2015, 11:25
alvaro_cistierna
 
Fecha de Ingreso: febrero-2011
Ubicación: Irlanda
Mensajes: 1
Antigüedad: 13 años, 3 meses
Puntos: 0
Problema con la API IndexedDB

Buenas,

tengo un problema al utilizar la API InexedDB de HTML5. El error me sale al agregar un elemento a la base de datos:

Uncaught NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.

Dejo el codigo que tengo por si alguien me puede ayudar:

/*********************/


var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;

function iniciar(){
cajadatos=document.getElementById('cajadatos');
var boton=document.getElementById('grabar');
boton.addEventListener('click', agregarobjeto, false);

if('webkitIndexedDB' in window){
window.indexedDB=window.webkitIndexedDB;
window.IDBTransaction=window.webkitIDBTransaction;
window.IDBKeyRange=window.webkitIDBKeyRange;
window.IDBCursor=window.webkitIDBCursor;
}else if('mozIndexedDB' in window){
window.indexedDB=window.mozIndexedDB;
}

var solicitud=indexedDB.open('mibase');
solicitud.addEventListener('error', errores, false);
solicitud.addEventListener('success', crear, false);
}

function errores(e){
alert('Error: '+e.code+' '+e.message);
}

function crear(e){
bd=e.result || e.target.result;
if(bd.version==''){
var solicitud=bd.setVersion('1.0');
solicitud.addEventListener('error', errores, false);
solicitud.addEventListener('success', crearbd, false);
}
}

function crearbd(){
var almacen=bd.createObjectStore('peliculas',{keyPath: 'id'});
almacen.createIndex('BuscarFecha', 'fecha',{unique: false});
}

function agregarobjeto(){
var clave=document.getElementById('clave').value;
var titulo=document.getElementById('texto').value;
var fecha=document.getElementById('fecha').value;

var transaccion=bd.transaction(['peliculas'],IDBTransaction.READ_WRITE);
// var transaccion = bd.transaction(["peliculas"], "readwrite");
var almacen=transaccion.objectStore('peliculas');
var solicitud=almacen.add({id: clave, nombre: titulo, fecha: fecha});
solicitud.addEventListener('success', function(){
mostrar(clave) }, false);
document.getElementById('clave').value='';
document.getElementById('texto').value='';
document.getElementById('fecha').value='';
}

/************************************/

He probado de varias formas que he visto en la red pero no doy con la solucion.

Un saludo y gracias