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

IDBTransaction: abort() Methode - 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: abort() Methode

Baseline
Weitgehend verfgbar

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

Hinweis: Diese Funktion ist in Web Workers verfgbar.

Die abort() Methode des IDBTransaction-Interfaces macht alle nderungen an Objekten in der mit dieser Transaktion verbundenen Datenbank rckgngig.

Alle whrend dieser Transaktion erstellten ausstehenden IDBRequest-Objekte haben ihr IDBRequest.error-Attribut auf einen AbortError-DOMException gesetzt.

In diesem Artikel

Syntax

js
abort()

Parameter

Keine.

Rckgabewert

Keine (undefined).

Ausnahmen

InvalidStateError DOMException

Wird ausgelst, wenn die Transaktion bereits abgeschlossen oder abgebrochen wurde.

Beispiele

Im folgenden Codebeispiel ffnen wir eine Lese-/Schreib-Transaktion auf unserer Datenbank und fgen einem Objektspeicher einige Daten hinzu. Beachten Sie auch die an die Transaktions-Ereignishandler angehngten Funktionen, um das Ergebnis der Transaktionsffnung im Falle eines Erfolgs oder Fehlers zu berichten. Am Ende brechen wir alle unter der aktuellen Transaktion durchgefhrten Aktivitten mit abort() ab. Fr ein vollstndiges Arbeitsbeispiel siehe unsere To-do-Benachrichtigungen 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. Duplicate items not allowed.";
  };

  // 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.";
  };

  // Abort the transaction we just did
  transaction.abort();
}

Spezifikationen

Spezifikation
Indexed Database API 3.0
# dom-idbtransaction-abort

Browser-Kompatibilitt

Siehe auch


Web Proxy Viewer  |  New URL  |  Original Page