0

I need help with indexedDB.

I am trying to get data from indexedDB with key. But this result I need at outside function.

   function getText(){
       return getFromIndexedDB('userData','Test');
    }
    
    
    function getFromIndexedDB(type, key) {
        if (key === "") return false;

    var transaction = db.transaction([type], "readonly");
    var store = transaction.objectStore(type);

    var request = store.get(key);

    request.onsuccess = function(e) {
        return e.target.result;
     }
    request.onerror = function (e) {
        console.log("Error");
        console.dir(e);
    }
}
  • you can use callback, promise or async await. Wrap getFromIndexedDB with any of these methods and call it wherever you want. – Rinkesh Golwala Jul 15 '20 at 18:18
  • Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Josh Jul 15 '20 at 19:47

0 Answers0