Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Experiment: Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten.

IDBTransaction: commit()-Methode

BaselineWidely available

Hinweis: Diese Funktion ist inWeb Workers verfügbar.

Diecommit()-Methode desIDBTransaction-Interfaces bestätigt die Transaktion, wenn sie auf einer aktiven Transaktion aufgerufen wird.

Beachten Sie, dasscommit() normalerweise nichtaufgerufen werden muss – eine Transaktion wird automatisch bestätigt, wenn alle ausstehenden Anfragen erfüllt sind und keine neuen Anfragen gestellt wurden.commit() kann verwendet werden, um den Bestätigungsprozess zu starten, ohne auf Ereignisse von ausstehenden Anfragen zu warten.

Wenn es auf einer Transaktion aufgerufen wird, die nicht aktiv ist, wird einInvalidStateErrorDOMException ausgelöst.

Syntax

js
commit()

Parameter

Keine.

Rückgabewert

Keiner (undefined).

Ausnahmen

InvalidStateErrorDOMException

Wird ausgelöst, wenn der Transaktionszustand nicht aktiv ist.

Beispiele

js
const note = document.getElementById("notifications");// open a read/write db transaction, ready for adding the dataconst transaction = db.transaction(["myDB"], "readwrite");// report on the success of opening the transactiontransaction.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 transactionconst objectStore = transaction.objectStore("myObjStore");// add our newItem object to the object storeconst 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.";};// Force the changes to be committed to the database asaptransaction.commit();

Spezifikationen

Specification
Indexed Database API 3.0
# ref-for-dom-idbtransaction-commit②

Browser-Kompatibilität

Siehe auch

MDN-Feedback-Box

Diese Seite wurde automatisch aus dem Englischen übersetzt.


[8]ページ先頭

©2009-2025 Movatter.jp