HTML5 IndexedDB Example

JavascriptWeb DevelopmentFront End Scripts

The following function is an example of IndexedDB to add data:

function add() {
   var request = db.transaction(["employee"], "readwrite")
   .objectStore("employee")
   .add({ id: "001", name: "Amit", age: 28, email: "demo1@example.com" });
   request.onsuccess = function(event) {
      alert("Amit has been added to your database.");
   };
   request.onerror = function(event) {
      alert("Unable to add data\r\nAmit is already exist in your database! ");
   }
}

Above, we added the following details in the database:

const employeeData = [
   { id: "001", name: "Amit", age: 28, email: "demo1@example.com" },
];
raja
Published on 11-Apr-2018 11:32:12
Advertisements