I have a javascript codeblock for Indexeddb call, see below
Link to sample:
https://test.quality-auditors.com/IndexedDB/?
I have found some sites on it, but i could not really identify how to solve it, maybe somebody can give me babysteps.
When I call this function, I recieve the reply immediatly, the function does not wait for the request.onsuccess to complete when finishing the function
So when i call this function, i cannot the recieve the final value, somehow I need to get the function to wait till the request.onsuccess has completed. Can someone add just the lines of code so this would work.
I have added a callback , but this fires bevore the onsuccess routine calls the callback - it replies to the call in the line var request = objectStore.get(cursorkey)
;
alert('call at start: ' + getmyitem('a2d9592e-11c7-4
d20-cccd-d
d293988ce8
6'));
function getmyitem(myuuid) {
readitem(myuuid, function (dataset) {
alert('Data in getmyitem: ' + dataset);
return dataset
});
}
function readitem(cursorkey, callback) {
alert("Readdetails "+cursorkey);
var transaction = db.transaction(["note"]);
var objectStore = transaction.objectStore("n
ote");
var request = objectStore.get(cursorkey)
;
request.onerror = function (event) {
callback('error');
console.dir(event);
};
request.onsuccess = function(event) {
var note = request.result;
document.getElementById("n
oteDetail"
).innerHTM
L = "<h2>"+note.title+"</h2><p
>"+note.bo
dy+"</p>";
//$("#noteDetail").html("<
h2>"+note.
title+"</h
2><p>"+not
e.body+"</
p>");
alert("Readdetails2 " + note.title);
callback(note.title);
//return note.title;
};
}
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.