[英]Server sent event, how many event source can i create
I have a database containing users details, then listing them separately in a page. 我有一个包含用户详细信息的数据库,然后在页面中单独列出它们。 I am using the server sent event to call them. 我正在使用服务器发送的事件来调用它们。 But each time i am initializing. 但是每次我初始化时。 Is it right to do so? 这样做对吗?
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);
And the next data: 和下一个数据:
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.