[英]Server sent event, how many event source can i create
我有一個包含用戶詳細信息的數據庫,然后在頁面中單獨列出它們。 我正在使用服務器發送的事件來調用它們。 但是每次我初始化時。 這樣做對嗎?
if (!!window.EventSource) {
var source = new EventSource("get_vacation_days.php");
} else {
alert("Your browser does not support Server-sent events! Please upgrade it!");
}
source.addEventListener("message", function(e) {
getVacationDays(e.data);
}, false);
source.addEventListener("open", function(e) {
console.log("Connection was opened.");
}, false);
source.addEventListener("error", function(e) {
console.log("Error: " );
console.log(e);
}, false);
和下一個數據:
if (!!window.EventSource) {
var source = new EventSource("get_days_in_company.php");
} else {
alert("Your browser does not support Server-sent events! Please upgrade it!");
}
source.addEventListener("message", function(e) {
getDaysInCompany(e.data);
}, false);
source.addEventListener("open", function(e) {
console.log("Connection was opened.");
}, false);
source.addEventListener("error", function(e) {
console.log("Error: " );
console.log(e);
}, false);
您可以有多個EventSource,唯一的限制是您要多么努力地使用客戶端的瀏覽器以及基礎架構可以處理多少個打開的連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.