.connection美元.中心未赋值

本文关键字:赋值 美元 connection | 更新日期: 2023-09-27 17:52:50

我在框架4.0中使用信号r。当我调用我的集线器类(testhub)它显示未定义。我的jquery代码如下

<head runat="server">
        <title></title>
        <script src='<%: ResolveClientUrl("Scripts/jquery-1.6.4.js") %>'></script>
             <script src='<%: ResolveClientUrl("Scripts/jquery-1.6.4.min.js") %>'></script>
             <script src='<%: ResolveClientUrl("Scripts/jquery.signalR-1.0.0-rc1.js") %>'></script>   
            <script src='<%: ResolveClientUrl("Scripts/jquery.signalR-1.0.0-rc1.min.js") %>'></script>
             <script src='<%: ResolveClientUrl("signalr/hubs") %>'></script>
    </head>
    <body>
        <form id="form1" runat="server">
    var data = $.connection.tenantHub;
                    $.connection.hub.logging = true;
                    console.log(data); //undefine
            </script>
    </form>

我有global。在

上没有任何错误
void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        RouteTable.Routes.MapHubs();
    }  

我在Hubs文件夹中有hub类,如下所示。

[HubName("tenantHub")]
public class testhub:Hub
{
    public void send(string message)
    {
        Clients.All.addmessage(message);
    }
}

我的包如下

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="jQuery" version="1.6.4" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR" version="1.0.0-rc1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.Core" version="1.0.0-rc1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.JS" version="1.0.0-rc1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.Owin" version="1.0.0-rc1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.SystemWeb" version="1.0.0-rc1" targetFramework="net40" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="1.0-rc1" targetFramework="net40" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
  <package id="Newtonsoft.Json" version="4.5.4" targetFramework="net40" />
  <package id="Owin" version="1.0" targetFramework="net40" />
</packages>

.connection美元.中心未赋值

最后一个兼容。net Framework 4.0的signalr版本是1.2.2:

你可以尝试通过打开NuGet包管理器控制台并输入:

来更新你的Signalr版本吗?
Install-Package Microsoft.AspNet.SignalR.Client -Version 1.2.2
Install-Package Microsoft.AspNet.SignalR -Version 1.2.2

基于jquery 1.6.4 Fwk 4和signalr1的完整聊天示例:http://www.bluelemoncode.com/2013/02/default.aspx

此外,不要解析两次js脚本(根据您的环境只保留最小化或未压缩):

<script src='<%: ResolveClientUrl("Scripts/jquery-1.6.4.min.js") %>'></script>                 
<script src='<%: ResolveClientUrl("Scripts/jquery.signalR-1.0.0-rc1.min.js") %>'></script>