| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/de/docs/Web/API/IDBTransaction/abort | [Back] [Original] |
Get to know MDN better
Dieser Inhalt wurde automatisch aus dem Englischen bersetzt, und kann Fehler enthalten. Erfahre mehr ber dieses Experiment.
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.
abort()
Keine.
Keine (undefined).
InvalidStateError DOMExceptionWird ausgelst, wenn die Transaktion bereits abgeschlossen oder abgebrochen wurde.
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).
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();
}
| Spezifikation |
|---|
| Indexed Database API 3.0 # dom-idbtransaction-abort |
IDBDatabaseIDBTransactionIDBKeyRangeIDBObjectStoreIDBCursorIDBTransactionDer Bauplan fr ein besseres Internet.
Teile dieses Inhalts sind 19982026 von einzelnen mozilla.org-Mitwirkenden. Inhalte sind verfgbar unter einer Creative-Commons-Lizenz.
| Web Proxy Viewer | New URL | Original Page |