IDBTransaction.commit() - Web APIs | MDN
source link: https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction/commit
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
IDBTransaction.commit()
The commit()
method of the IDBTransaction
interface commits the transaction if it is called on an active transaction.
Note that commit()
doesn't normally have 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 an InvalidStateError
DOMException
.
Note: This feature is available in Web Workers
Syntax
transaction.commit();
Parameters
None.
Return value
Void.
Exceptions
InvalidStateError
The transaction state is not active.
Examples
// open a read/write db transaction, ready for adding the data var transaction = db.transaction(["myDB"], "readwrite"); // report on the success of opening the transaction transaction.oncomplete = function(event) { note.innerHTML += '<li>Transaction completed: database modification finished.</li>'; }; transaction.onerror = function(event) { note.innerHTML += '<li>Transaction not opened due to error. Duplicate items not allowed.</li>'; }; // create an object store on the transaction var objectStore = transaction.objectStore("myObjStore"); // add our newItem object to the object store var objectStoreRequest = objectStore.add(newItem[0]); objectStoreRequest.onsuccess = function(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.innerHTML += '<li>Request successful.</li>'; }; // Force the changes to be committed to the database asap transaction.commit();
Specifications
SpecificationIndexed Database API 3.0 (Indexed DB 3.0)# ref-for-dom-idbtransaction-commit②
Browser compatibility
Report problems with this compatibility data on GitHubdesktopmobileChromeEdgeFirefoxInternet ExplorerOperaSafariWebView AndroidChrome AndroidFirefox for AndroidOpera AndroidSafari on iOSSamsung Internetcommit
Legend
See also
- Using IndexedDB
- Starting transactions:
IDBDatabase
- Using transactions:
IDBTransaction
- Setting a range of keys:
IDBKeyRange
- Retrieving and making changes to your data:
IDBObjectStore
- Using cursors:
IDBCursor
- Reference example: To-do Notifications (view example live.)
Recommend
-
66
The OffscreenCanvas interface provides a canvas that can be rendered off screen. It is available in both the window and worker contexts.
-
7
Contributing to the content of MDN Web Docs First of all, thanks for taking the time to contribute to
-
5
MediaDevices.getUserMedia() The MediaDevices.getUserMedia() method prompts the user for permission t...
-
1
CrashReportBody Experimental This is an experimental technologyCheck th...
-
4
StorageManager.estimate()Secure contextThis feature is available only in secure contexts (HTTPS), in some or all
-
5
IDBCursor.continue() The continue() method of the IDBCursor interface advances the cursor to the next positio...
-
5
IDBKeyRange The IDBKeyRange interface of the IndexedDB API represents a continuous interval over some data type th...
-
9
HTMLMediaElement.canPlayType() The HTMLMediaElement method canPlayType() reports how likely it is tha...
-
4
ServiceWorkerGlobalScopeThe ServiceWorkerGlobalScope interface of the Service Worker API represents the global...
-
4
MediaStreamAudioDestinationNodeThe MediaStreamAudioDestinationNode interface represents an audio destination consisting of a WebRTC
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK