信号通知
Signal r notification
我正在创建一个使用信号 r 发送通知的应用程序。我正在使用 VS 2012。在我的通知视图中,我在 @model App.Models.Notification
.
中添加了以下代码
@{
ViewBag.Title = "Index";
}
@section Scripts
{
<script src="/Scripts/jquery-1.8.20.min.js"></script>
<script src="~/Scripts/jquery.signalR-2.2.0.js"></script>
<script src="/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
var proxy = $.connection.notificationHub;
alert(proxy);
$("#button1").click(function () {
alert($("#text1").val());
proxy.server.sendNotifications($("#text1").val());
alert(12);
});
$.connection.hub.start();
alert(14);
});
</script>
}
<h2>Index</h2>
@using (Html.BeginForm())
{
<input id="text1" type="text" />
<input id="button1" type="submit" value="Send" />
}
点击按钮后,sendNotifications()
没有被调用,通知也没有发送给客户端。
这是中心 class
public class NotificationHub : Hub
{
public void Hello()
{
Clients.All.hello();
}
public void SendNotifications(string message)
{
Clients.All.receiveNotification(message);
}
}
谁能帮我解决一下
您还需要创建一个 owin 启动 class。我会把代码放在这里(和你的一样):-
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.signalR-2.1.2.min.js"></script>
<script src="/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
var proxy = $.connection.notificationHub;
alert(proxy);
$("#button1").click(function () {
alert($("#text1").val());
proxy.server.sendNotifications($("#text1").val());
alert(12);
});
$.connection.hub.start();
alert(14);
});
</script>
通知中心喜欢:
public class NotificationHub : Hub
{
public void Hello()
{
Clients.All.hello();
}
public void SendNotifications(string message)
{
Clients.All.receiveNotification(message);
}
}
现在最重要的是你需要创建一个 owin 启动 class 来启动信号 r,代码如下:
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
我正在创建一个使用信号 r 发送通知的应用程序。我正在使用 VS 2012。在我的通知视图中,我在 @model App.Models.Notification
.
@{
ViewBag.Title = "Index";
}
@section Scripts
{
<script src="/Scripts/jquery-1.8.20.min.js"></script>
<script src="~/Scripts/jquery.signalR-2.2.0.js"></script>
<script src="/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
var proxy = $.connection.notificationHub;
alert(proxy);
$("#button1").click(function () {
alert($("#text1").val());
proxy.server.sendNotifications($("#text1").val());
alert(12);
});
$.connection.hub.start();
alert(14);
});
</script>
}
<h2>Index</h2>
@using (Html.BeginForm())
{
<input id="text1" type="text" />
<input id="button1" type="submit" value="Send" />
}
点击按钮后,sendNotifications()
没有被调用,通知也没有发送给客户端。
这是中心 class
public class NotificationHub : Hub
{
public void Hello()
{
Clients.All.hello();
}
public void SendNotifications(string message)
{
Clients.All.receiveNotification(message);
}
}
谁能帮我解决一下
您还需要创建一个 owin 启动 class。我会把代码放在这里(和你的一样):-
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.signalR-2.1.2.min.js"></script>
<script src="/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
var proxy = $.connection.notificationHub;
alert(proxy);
$("#button1").click(function () {
alert($("#text1").val());
proxy.server.sendNotifications($("#text1").val());
alert(12);
});
$.connection.hub.start();
alert(14);
});
</script>
通知中心喜欢:
public class NotificationHub : Hub
{
public void Hello()
{
Clients.All.hello();
}
public void SendNotifications(string message)
{
Clients.All.receiveNotification(message);
}
}
现在最重要的是你需要创建一个 owin 启动 class 来启动信号 r,代码如下:
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}