Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

IDBTransaction: commit() method

BaselineWidely available

Note: This feature is available inWeb Workers.

Thecommit() method of theIDBTransaction interface commits the transaction if it is called on an active transaction.

Note thatcommit() doesn't normallyhave to be called — a transaction will automatically commit when all outstanding requests have been satisfied and no new requests have been made.commit() can be used to start the commit process without waiting for events from outstanding requests to be dispatched.

If it is called on a transaction that is not active, it throws anInvalidStateErrorDOMException.

Syntax

js
commit()

Parameters

None.

Return value

None (undefined).

Exceptions

InvalidStateErrorDOMException

Thrown if the transaction state is not active.

Examples

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();

Specifications

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

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp