Jquery 信号器呼叫挂起浏览器
以此为例,, 我有上面的信号员代码。当我在本地机器上运行它时,它工作正常,但是当我在IIS上部署它并使用多个用户进行测试时,浏览器没有响应 你能告诉我这件事哪里出了问题吗 枢纽Jquery 信号器呼叫挂起浏览器,jquery,asp.net-mvc,signalr,Jquery,Asp.net Mvc,Signalr,以此为例,, 我有上面的信号员代码。当我在本地机器上运行它时,它工作正常,但是当我在IIS上部署它并使用多个用户进行测试时,浏览器没有响应 你能告诉我这件事哪里出了问题吗 枢纽 我认为通过查看您的代码,您需要去掉GetMyMessage REST服务调用的逻辑,并尝试将其移动到hub方法updateMessages中,这将是您@JenishZinzuvadiya的最佳参考,我的代码运行良好。一旦sql表中有更改,它就会显示通知。问题是,当多个用户连接时,呼叫是重复的。有时,一次更改调用GetM
我认为通过查看您的代码,您需要去掉GetMyMessage REST服务调用的逻辑,并尝试将其移动到hub方法updateMessages中,这将是您@JenishZinzuvadiya的最佳参考,我的代码运行良好。一旦sql表中有更改,它就会显示通知。问题是,当多个用户连接时,呼叫是重复的。有时,一次更改调用GetMyMessages 25次,这种情况并不经常发生
$(function () {
// Declare a proxy to reference the hub.
var notifications = $.connection.messagesHub;
//debugger;
// Create a function that the hub can call to broadcast messages.
notifications.client.updateMessages = function () {
getMyMessages();
};
// Start the connection.
$.connection.hub.start().done(function () {
//alert("connection started");
getMyMessages();
}).fail(function (e) {
alert(e);
});
});
function getMyMessages() {
var tbl = $('#mesTable');
$.ajax({
url: '/Home/GetMyMessages',
contentType: 'application/html ; charset:utf-8',
type: 'GET',
dataType: 'html'
}).success(function (result) {
tbl.empty().append(result);
}).error(function () {
});
}
[HubMethodName("sendMessages")]
public static void SendMyMessages()
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MessagesHub>();
context.Clients.All.updateMessages();
}
----------------------------------------------------------------------
public IEnumerable<Messages> GetAllMessages()
{
var messages = new List<Messages>();
using (var connection = new SqlConnection(_connString))
{
connection.Open();
using (var command = new SqlCommand(@"SELECT [DoctorId], [DisplayName], [EmptyMessage], [Date] FROM [dbo].[Messages]", connection))
{
command.Notification = null;
var dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
if (connection.State == ConnectionState.Closed)
connection.Open();
var reader = command.ExecuteReader();
while (reader.Read())
{
messages.Add(item: new DocNotification { Id = (int)reader["Id"], DoctorId = (int)reader["DoctorId"], DisplayName = reader["DisplayName"] != DBNull.Value ? (string)reader["Message"] : "";
}
}
}
return messages;
}
private void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
if (e.Type == SqlNotificationType.Change)
{
MessagesHub.SendMyMessages();
}
}