本文介绍了将Html5 SSE发送给特定客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将服务器事件(推送通知)发送给特定用户(基于他们的用户名)任何想法怎么做?

i want to send the server event(push notificaton) to specific users(based on their usernames) any idea how to do it?

推荐答案


string JSON = "data: {'IntendedFor' = 'AdminClerks', 'Message' = 'You\'ve got a server event'}";
Response.Write(JSON+'\n\n');
Response.Flush();





客户端HTML



Client HTML

<input id='myGroup' type='hidden' value='AdminClerk' />





客户端Javascript



Client Javascript

var myGroup = document.GetElementById('myGroup').value;
var source = new EventSource('<insert url="" here="">');
source.onmessage = function (e) {
  var myJSONResponse = JSON.parse(e.data);
  if (myJSONResponse.IntendedFor == myGroup)
    alert("You've got a server event");
}


这篇关于将Html5 SSE发送给特定客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:40