commit()
方法在
IDBTransaction
interface commits the transaction if it is called on an active transaction.
注意,
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
.
transaction.commit();
None.
Void.
| 异常 | 描述 |
|---|---|
InvalidStateError
|
The transaction state is not active. |
// 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();
| 规范 | 状态 | 注释 |
|---|---|---|
|
索引数据库 API 草案
The definition of 'IDBTransaction.commit()' in that specification. |
推荐 | Unitial definition. |
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
更新 GitHub 上的兼容性数据| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
commit
|
Chrome 76 | Edge 79 | Firefox 74 | IE No | Opera 63 | Safari No | WebView Android 76 | Chrome Android 76 | Firefox Android No | Opera Android 54 | Safari iOS No | Samsung Internet Android 12.0 |
完整支持
不支持
IDBDatabase
IDBTransaction
IDBKeyRange
IDBObjectStore
IDBCursor
IDBTransaction
abort()
commit()
objectStore()
IDBCursor
IDBCursorSync
IDBCursorWithValue
IDBDatabase
IDBDatabaseException
IDBDatabaseSync
IDBEnvironment
IDBEnvironmentSync
IDBFactory
IDBFactorySync
IDBIndex
IDBIndexSync
IDBKeyRange
IDBObjectStore
IDBObjectStoreSync
IDBOpenDBRequest
IDBRequest
IDBTransactionSync
IDBVersionChangeEvent
IDBVersionChangeRequest