SignalR无法正常工作

时间:2016-11-17 09:31:08

标签: jquery html signalr

我开始使用SignalR,所以我正在关注这个旧的构建事件:https://channel9.msdn.com/Events/Build/2012/3-034。我在我的机器上一步一步地按照演示它不能正常工作。我正在使用VS 2015社区版和Update 3,jquery-1.12.4,jquery-ui.1.12.1和jquery.signalR-2.2.1。我创建了一个空网站并添加了以下组件

MoveShapeHub.cs :(它在根上)

using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;

namespace Study.SignalR
{
    [HubName("moveShape")]
    public class MoveShapeHub : Hub
    {
        public void MoveShape(int x, int y)
        {
            Clients.Others.shapeMoved(x, y);
        }
    }
}

moveShape.js(它位于名为MoveShape的文件夹中)

/// <reference path="../Scripts/jquery-1.12.4.js" />
/// <reference path="../Scripts/jquery.signalR-2.2.1.js" />
/// <reference path="../Scripts/jquery-ui-1.12.1.js" />

$(function () {

    var hub = $.connection.moveShape;
    $shape = $("#shape");
    hub.client.shapeMoved = function (x, y) {
        $shape.css({ left: x, top: y });
    };

    $.connection.hub.start().done(function () {
        $shape.draggable({
            drag: function () {
                hub.server.moveShape(this.offsetLeft, this.offsetTop || 0)
            }
        });
    });
});

index.html(它位于名为MoveShape的文件夹中)

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <style>
        #shape{
            width:100px; height:100px; background-color:#b200ff; cursor: move;
        }
    </style>
</head>
<body>
    <div id="shape">

    </div>

    <script src="../Scripts/jquery-1.12.4.js"></script>
    <script src="../Scripts/jquery-ui-1.12.1.js"></script>
    <script src="../Scripts/jquery.signalR-2.2.1.js"></script>
    <script src="/signalr/hubs"></script>
    <script src="MoveShape/moveShape.js"></script>
</body>
</html>

我做错了什么?

0 个答案:

没有答案