[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/de/docs/Web/API/IDBTransaction/error [Back]  [Original]

IDBTransaction: error Eigenschaft - Web-APIs | MDN

Dieser Inhalt wurde automatisch aus dem Englischen bersetzt, und kann Fehler enthalten. Erfahre mehr ber dieses Experiment.

View in English Always switch to English

IDBTransaction: error Eigenschaft

Baseline Weitgehend verfgbar *

Diese Funktion ist gut etabliert und funktioniert auf vielen Gerten und in vielen Browserversionen. Sie ist seit Juli 2015 browserbergreifend verfgbar.

* Einige Teile dieser Funktion werden mglicherweise unterschiedlich gut untersttzt.

Hinweis: Diese Funktion ist in Web Workers verfgbar.

Die IDBTransaction.error Eigenschaft des IDBTransaction Interfaces gibt den Fehlertyp zurck, wenn eine Transaktion erfolglos ist.

In diesem Artikel

Wert

Ein DOMException, das den relevanten Fehler enthlt, oder null, falls keiner vorhanden ist.

Es kann ein Verweis auf denselben Fehler wie das Anforderungsobjekt sein, das ihn ausgelst hat, oder ein Transaktionsfehler (zum Beispiel QuotaExceededError).

Diese Eigenschaft ist null, wenn die Transaktion nicht abgeschlossen ist oder abgeschlossen und erfolgreich festgeschrieben wurde.

Beispiele

Im folgenden Codebeispiel ffnen wir eine Lese-/Schreibtransaktion auf unserer Datenbank und fgen einem Objektspeicher einige Daten hinzu. Beachten Sie auch die Funktionen, die an die Transaktionsereignishandler angehngt sind, um das Ergebnis der Transaktionsffnung im Falle eines Erfolgs oder Fehlschlags zu berichten. Beachten Sie den Block transaction.onerror = (event) => { };, der transaction.error verwendet, um zu helfen, zu berichten, was schiefgelaufen ist, wenn die Transaktion erfolglos war. Fr ein vollstndiges funktionierendes Beispiel, siehe unsere To-do Notifications App (Beispiel live ansehen).

js
const note = document.getElementById("notifications");

// an instance of a db object for us to store the IDB data in
let db;

// Let us open our database
const DBOpenRequest = window.indexedDB.open("toDoList", 4);

DBOpenRequest.onsuccess = (event) => {
  note.appendChild(document.createElement("li")).textContent =
    "Database initialized.";

  // store the result of opening the database in the db variable.
  // This is used a lot below
  db = DBOpenRequest.result;

  // Run the addData() function to add the data to the database
  addData();
};

function addData() {
  // Create a new object ready for being inserted into the IDB
  const newItem = [
    {
      taskTitle: "Walk dog",
      hours: 19,
      minutes: 30,
      day: 24,
      month: "December",
      year: 2013,
      notified: "no",
    },
  ];

  // open a read/write db transaction, ready for adding the data
  const transaction = db.transaction(["toDoList"], "readwrite");

  // report on the success of opening the transaction
  transaction.oncomplete = (event) => {
    note.appendChild(document.createElement("li")).textContent =
      "Transaction completed: database modification finished.";
  };

  transaction.onerror = (event) => {
    note.appendChild(document.createElement("li")).textContent =
      `Transaction not opened due to error: ${transaction.error}`;
  };

  // create an object store on the transaction
  const objectStore = transaction.objectStore("toDoList");

  // add our newItem object to the object store
  const objectStoreRequest = objectStore.add(newItem[0]);

  objectStoreRequest.onsuccess = (event) => {
    // report the success of the request (this does not mean the item
    // has been stored successfully in the DB - for that you need transaction.onsuccess)
    note.appendChild(document.createElement("li")).textContent =
      "Request successful.";
  };
}

Spezifikationen

Spezifikation
Indexed Database API 3.0
# ref-for-dom-idbtransaction-error

Browser-Kompatibilitt

Siehe auch


Web Proxy Viewer  |  New URL  |  Original Page