Search code examples
jqueryhtmllocal-storageindexeddboffline-caching

HTML5 Indexeddb commands to read the data is not supporting in the Ipad Safari (version 8.1)


Query Description:-

This question is particularly with the issues that I am facing in reading the indexeddb data in the Ipad Safari 8.1. I am able to create Indexeddb and insert the data into it. But unable to read the same in Ipad safari.

Below is the code format that I tried - 1. Using Cursors

var database = window.indexedDB.open(databaseName);
if (database) {
            database.onsuccess = function (event) { 
                var transaction =     event.currentTarget.result.transaction(ObjectStoreName, "readonly");
                var objectStore = transaction.objectStore(ObjectStoreName);
                var index = objectStore.index(“IndexName”);

var request = index.openCursor(“Search_Keyword”);    // Cursors not working. Getting null here.
                request.onsuccess = function (event) {
                        var cursor = event.target.result;
                        if (cursor) {
                            var abc=cursor.value.ColumnName;
}
};

                request.onerror = function (event) {
                    alert(‘Error’);  // It is strange that, I never got any error relating to the way used to read the indexeddb data.
                };
  1. Using get method.

    var database = window.indexedDB.open(databaseName);

        if (database) {
            database.onsuccess = function (event) { 
                var transaction = event.currentTarget.result.transaction(ObjectStoreName, "readonly");
                var objectStore = transaction.objectStore(ObjectStoreName);
                var index = objectStore.index(“IndexName”);
                var processCompelted = false;
                var request = index.get(TableIndex);
                request.onsuccess = function (event) {
                    alert('index.get is working');                               // able to come inside
                    alert(event);              // returns request object
                    alert(event.target);  //returns null
                    alert(event.target.result); //getting null value
                    alert(request);          // returns request object
                    alert(request.result);  //getting null value
                };
                request.onerror = function (event) {
                    alert(‘Error’);  // It is strange that, I never got any error relating to the way used to read the indexeddb data.
                };
    

Please let me know is there any way to read the data from the indexeddb in ipad safari browser. Or let me know if I have done any mistakes in write the code above.


Solution

  • Are you sure that the records you want to get are stored successfully before getting it ?

    It seems that the implementation of indexedDB in Safari mobile is buggy (http://caniuse.com/#search=indexeddb) and that no error is thrown when it fails to store a record...

    So in your case, perhaps your get is successfully executed but return nothing because no records are stored.

    Here (http://www.raymondcamden.com/2014/9/25/IndexedDB-on-iOS-8--Broken-Bad) are some tests, made with Safari Mobile, that shows the bugs. He gives answer on how to make this work too. The solution is by creating the id by yourself and forcing it when inserting your record. Read the article for more informations.