aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/idbrequest/onsuccess/index.html
blob: 536aa9ab8177fdbd27807b2e7066c1b4926aa220 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
title: IDBRequest.onsuccess
slug: Web/API/IDBRequest/onsuccess
tags:
  - API
  - Database
  - IDBRequest
  - IndexedDB
  - Property
  - Reference
  - Storage
  - onsuccess
translation_of: Web/API/IDBRequest/onsuccess
---
<p>{{ APIRef("IndexedDB") }}</p>

<div>
<p>{{domxref("IDBRequest")}} インターフェースの<strong><code>onsuccess</code></strong>イベントハンドラはリクエストの結果が正常に帰ってきた時に着火される<code><a href="/ja/docs/Web/API/IDBRequest/success_event">success</a></code>イベントをハンドリングします。</p>

<p>イベントハンドラは、type="success"の成功<a dir="ltr" href="/ja/docs/Web/Events/success">イベント</a>をパラメータとして受け取ります。</p>

<p>{{AvailableInWorkers}}</p>
</div>

<h2 id="構文">構文</h2>

<pre class="syntaxbox" style="font-size: 14px;">request.onsuccess = function(event) { ... };</pre>

<h2 id="例"></h2>

<p>下記の例は、指定されたレコードタイトルをリクエストします。リクエストの<code>onsuccess</code>イベントハンドラは{{domxref("IDBObjectStore")}} (<code>objectStoreTitleRequest.result</code>として利用可能)からレコードを取得し、そのプロパティを更新してオブジェクトストアに書き戻します。</p>

<p>完全な例は<span style="line-height: 1.5;"> </span><a href="https://github.com/mdn/to-do-notifications/" style="line-height: 1.5;">To-do Notifications</a><span style="line-height: 1.5;"> app (</span><a href="http://mdn.github.io/to-do-notifications/" style="line-height: 1.5;">example live</a>)を参照してください。</p>

<pre class="brush: js;highlight:[11]" style="font-size: 14px;">var title = "Walk dog";

// いつものようにトランザクションをオープンする
var objectStore = db.transaction(['toDoList'], "readwrite").objectStore('toDoList');

// title変数の値をタイトルとして持つTo-Doリストオブジェクトを取得する
var objectStoreTitleRequest = objectStore.get(title);

objectStoreTitleRequest.onsuccess = function() {
<code>  // resultとして返却されたデータオブジェクトを取得
  var data = objectStoreTitleRequest.result;

  // データオブジェクトのnotifiedプロパティ値を"yes"に更新する
  data.notified = "yes";</code>

  // データベースにアイテムを書き戻す別のリクエストを作成する
  var updateTitleRequest = objectStore.put(data);

  // この新しいリクエストが成功すると、
  // 表示更新のためにdisplayData()が再度実行される
  <span style="font-size: 1rem;">updateTitleRequest</span><span style="font-size: 1rem;">.onsuccess = function() {</span>
    displayData();
  };
};</pre>

<h2 id="仕様書">仕様書</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">仕様書</th>
   <th scope="col">状態</th>
   <th scope="col">備考</th>
  </tr>
  <tr>
   <td>{{SpecName('IndexedDB', '#widl-IDBRequest-onsuccess', 'onsuccess')}}</td>
   <td>{{Spec2('IndexedDB')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName("IndexedDB 2", "#dom-idbrequest-onsuccess", "onsuccess")}}</td>
   <td>{{Spec2("IndexedDB 2")}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの対応</h2>

<div>


<p>{{Compat("api.IDBRequest.onsuccess")}}</p>
</div>

<h2 id="関連情報">関連情報</h2>

<ul>
 <li><a href="/ja/docs/Web/API/IndexedDB_API/Using_IndexedDB">Using IndexedDB</a></li>
 <li><a href="/ja/docs/Web/Events/success">Success Event</a></li>
 <li>Starting transactions: {{domxref("IDBDatabase")}}</li>
 <li>Using transactions: {{domxref("IDBTransaction")}}</li>
 <li>Setting a range of keys: {{domxref("IDBKeyRange")}}</li>
 <li>Retrieving and making changes to your data: {{domxref("IDBObjectStore")}}</li>
 <li>Using cursors: {{domxref("IDBCursor")}}</li>
 <li>Reference example: <a class="external" href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a> (<a class="external" href="http://mdn.github.io/to-do-notifications/">view example live</a>.)</li>
 <li><code><a href="/ja/docs/Web/API/IDBRequest/success_event">success</a></code> event</li>
</ul>