0x800a138f - JavaScript运行时错误:无法获取属性' PaymentHub'未定义或空引用的

时间:2015-09-24 06:29:48

标签: asp.net signalr

我是ASP.NET SignalR的一个重要新手,并且一直在尝试使用它来开发一个简单的应用程序,它可以实时显示对数据库所做的更改。

我在尝试运行该应用程序时遇到以下错误:

  

http://localhost:57702/第13行第52行未处理的异常   0x800a138f - JavaScript运行时错误:无法获取属性   ' PaymentHub'未定义或空引用

这是我的javascript:



@{
    ViewBag.Title = "Status";
}

<h2>Status</h2>

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>PaymentStatus</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")
    <script src="~/Scripts/jquery.signalR-2.0.0.min.js"></script>
    <script src="~/signalr/hubs" type="text/javascript"></script>
    <script type="text/javascript">

        $(function () {

            // Proxy created on the fly
            var job = $.connection.PaymentHub;

            // Declare a function on the job hub so the server can invoke it
            job.client.displayStatus = function () {
                getData();
            };

            // Start the connection
            $.connection.hub.start();
            getData();
        });

        function getData() {
            var $tbl = $('#tblPaymentInfo');
            $.ajax({
                url: '../api/values',
                type: 'GET',
                datatype: 'json',
                success: function (data) {
                    if (data.length > 0) {
                        $tbl.empty();
                        $tbl.append(' <tr><th>ID</th><th>Payment_ID</th><th>Payment_Received</th><th>Payment_Pending</th></tr>');
                        var rows = [];
                        for (var i = 0; i < data.length; i++) {
                            rows.push(' <tr><td>' + data[i].Payment_ID + '</td><td>' + data[i].Payment_Received + '</td><td>' + data[i].Payment_Pending + '</td><td>');
                        }
                        $tbl.append(rows.join(''));
                    }
                }
            });
        }
    </script>
</head>
<body>
    <div>
        <table id="tblPaymentInfo" style="text-align:center;margin-left:10px"></table>
    </div>
</body>
</html>
&#13;
&#13;
&#13;

我的中心看起来像这样:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Microsoft.AspNet.SignalR;
    using Microsoft.AspNet.SignalR.Hubs;

    namespace WebDatabaseUpdateSignalR
    {
        public class PaymentHub : Hub
        {
            public static void Show()
            {
                IHubContext context =       GlobalHost.ConnectionManager.GetHubContext<PaymentHub>();
                context.Clients.All.displayStatus();
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

var job = $.connection.PaymentHub;应该var job = $.connection.paymentHub;没有资本。默认情况下,在SignalR的JS部分,事情会得到骆驼。

希望这会有所帮助。祝你好运!