Response: ok プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
ok
は Response
インターフェイスの読み取り専用プロパティで、このレスポンスが(ステータスが 200-299 で)成功したかどうかを表す論理値です。
値
論理値です。
例
Fetch Response の例 (Fetch Response のライブ を参照)では、新しい Request
オブジェクトを、 Request()
コンストラクターを使用して作成し、 JPG のパスを渡します。次に fetch()
を使用してこのリクエストをフェッチし、 Response.blob
を使用してリクエストから blob を抽出し、 URL.createObjectURL()
を使用してオブジェクト URL を作成し、これを <img>
に表示します。
メモ: fetch()
ブロックの先頭で、レスポンスの ok
値をコンソールにログ出力します。
js
const myImage = document.querySelector("img");
const myRequest = new Request("flowers.jpg");
fetch(myRequest).then((response) => {
console.log(response.ok); // レスポンスが正常に返された場合に true を返します。
response.blob().then((myBlob) => {
const objectURL = URL.createObjectURL(myBlob);
myImage.src = objectURL;
});
});
仕様書
Specification |
---|
Fetch # ref-for-dom-response-ok② |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ok |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
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.