A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/ja/docs/Web/API/EventSource/EventSource below:

EventSource() - Web API | MDN

EventSource()

Baseline Widely available

EventSource() コンストラクターは、リモートリソースを表す新しく作成された EventSource を返します。

構文
new EventSource(url)
new EventSource(url, options)
引数
url

文字列で、イベント/メッセージを処理するリモートリソースの場所を表します。

options 省略可

新しいコネクションを構成するオプションを提供します。可能な項目は次のとおりです。

withCredentials 省略可

論理値で、既定値は false であり、 CORS の資格情報を include に設定すべきかどうかを示します。

例
const evtSource = new EventSource("sse.php");
const eventList = document.querySelector("ul");

evtSource.onmessage = (e) => {
  const newElement = document.createElement("li");

  newElement.textContent = `message: ${e.data}`;
  eventList.appendChild(newElement);
};

メモ: 完全な例は GitHub で見られます。 PHP を用いた簡単な SSE のデモ を参照してください。

仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4