aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/api/idbtransaction/onerror
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/fr/web/api/idbtransaction/onerror
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/fr/web/api/idbtransaction/onerror')
-rw-r--r--files/fr/web/api/idbtransaction/onerror/index.html171
1 files changed, 171 insertions, 0 deletions
diff --git a/files/fr/web/api/idbtransaction/onerror/index.html b/files/fr/web/api/idbtransaction/onerror/index.html
new file mode 100644
index 0000000000..18c08c9a57
--- /dev/null
+++ b/files/fr/web/api/idbtransaction/onerror/index.html
@@ -0,0 +1,171 @@
+---
+title: IDBTransaction.onerror
+slug: Web/API/IDBTransaction/onerror
+tags:
+ - API
+ - IndexedDB
+ - Propriété
+ - Reference
+translation_of: Web/API/IDBTransaction/onerror
+---
+<div>{{APIRef("IndexedDB")}}</div>
+
+<p>Le gestionnaire d'événement <strong><code>onerror</code></strong>, rattaché à l'interface {{domxref("IDBTransaction")}}, s'exécute au déclenchement d'un événement <code><a href="/fr/docs/Web/Events/error">error</a></code> lorsque la transaction échoue.</p>
+
+<p>{{AvailableInWorkers}}</p>
+
+<h2 id="Syntaxe">Syntaxe</h2>
+
+<pre class="brush: js">transaction.onerror = function() { ... };</pre>
+
+<h2 id="Exemple">Exemple</h2>
+
+<p>Dans le code suivant, on commence par ouvrir une connexion à la base de donnée. Grâce à cette connexion, on initialise une transaction en lecture/écriture grâce à <code>IDBTransaction</code> pour accéder au magasin d'objets intitulé <code>toDoList</code> et y ajouter un enregistrement via la méthode  {{domxref("IDBObjectStore.add")}}. On notera également l'utilisation du gestionnaire d'événements {{domxref("IDBTransaction.oncomplete")}}.</p>
+
+<p>Le gestionnaire d'événement <strong><code>onerror</code></strong> de la transaction affiche le code d'erreur de la propriété propriété {{domxref("IDBTransaction.error","error")}} sur la page.</p>
+
+<pre class="brush: js">// Connexion à la base de données
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+DBOpenRequest.onsuccess = function(event) {
+ note.innerHTML += '&lt;li&gt;Connexion établie.&lt;/li&gt;';
+
+ // On affecte la connexion à la variable db.
+ db = DBOpenRequest.result;
+
+ // On exécute la fonction addData () pour ajouter
+ // des données dans la base
+ addData();
+};
+function addData() {
+ // On crée un nouvel objet prêt à être emmagasiné
+ newItem = [ { taskTitle: "Walk dog", hours: 19, minutes: 30, day: 24, month: "December", year: 2013, notified: "no" } ];
+
+ // On ouvre une transaction de lecture / écriture
+ // pour traiter les données via la connexion
+ var transaction = db.transaction(["toDoList"], "readwrite");
+
+ // En cas de succès de l'ouverture de la transaction
+ // on utilise ce gestionnaire
+ transaction.oncomplete = function(event) {
+ note.innerHTML += '&lt;li&gt;Transaction terminée : modification de la base de données OK.&lt;/li&gt;';
+ };
+ // En cas d'échec de l'ouverture de la transaction
+ // on utilisera ce gestionnaire
+ transaction.onerror = function(event) {
+ note.innerHTML += '&lt;li&gt;L\'erreur: "' + transaction.error +'" s\'est produite, échec de la transaction.&lt;/li&gt;';
+ };
+
+ // On ouvre l'accès au magasin "toDoList" de la transaction
+ var objectStore = transaction.objectStore("toDoList");
+
+ // Enfin on ajoute un enregistrement
+ var objectStoreRequest = objectStore.add(newItem[0]);
+ objectStoreRequest.onsuccess = function(event) {
+ // On signale l'ajout de l'enregistrement
+ note.innerHTML += '&lt;li&gt;Enregistrement ajouté.&lt;/li&gt;';
+ };
+ };
+ </pre>
+
+<p class="note"><strong>Note :</strong> Pour un exemple de travail complet, voir l'application <a href="https://github.com/mdn/to-do-notifications/">To-do Notifications</a> (<a href="https://mdn.github.io/to-do-notifications/">exemple <em>live</em> disponible ici</a>).</p>
+
+<h2 id="Spécifications">Spécifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Spécification</th>
+ <th scope="col">État</th>
+ <th scope="col">Commentaires</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('IndexedDB', '#widl-IDBTransaction-ononerror', 'onerror')}}</td>
+ <td>{{Spec2('IndexedDB')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilité_avec_les_navigateurs">Compatibilité avec les navigateurs</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Fonctionnalité</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Support simple</td>
+ <td>23{{property_prefix("webkit")}}<br>
+ 24</td>
+ <td>10 {{property_prefix("moz")}}<br>
+ {{CompatGeckoDesktop("16.0")}}</td>
+ <td>10, en partie</td>
+ <td>15</td>
+ <td>7.1</td>
+ </tr>
+ <tr>
+ <td>Disponible via les <em>web workers</em></td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile("37.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Fonctionnalité</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Firefox OS</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Support simple</td>
+ <td>4.4</td>
+ <td>{{CompatGeckoMobile("22.0")}}</td>
+ <td>1.0.1</td>
+ <td>10</td>
+ <td>22</td>
+ <td>8</td>
+ </tr>
+ <tr>
+ <td>Disponible via les <em>web workers</em></td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile("37.0")}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="Voir_aussi">Voir aussi</h2>
+
+<ul>
+ <li><a href="/fr/docs/Web/API/API_IndexedDB/Using_IndexedDB">Manipuler IndexedDB</a></li>
+ <li>Démarrer des transactions : {{domxref("IDBDatabase")}}</li>
+ <li>Manipuler des transactions : {{domxref("IDBTransaction")}}</li>
+ <li>Définir un intervalle de clés : {{domxref("IDBKeyRange")}}</li>
+ <li>Récupérer des données et les modifier : {{domxref("IDBObjectStore")}}</li>
+ <li>Manipuler des curseurs : {{domxref("IDBCursor")}}</li>
+ <li>Exemple de référence pour IndexedDB : <a href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a></li>
+</ul>