venkatbaggu / signalrdatabasenotifications

SignalR Database update notifications in ASP.NET MVC using SQL Dependency
51 stars 46 forks source link

for my application Hub is not connected. #4

Open nibavsyed opened 7 years ago

nibavsyed commented 7 years ago

@@section Scripts{@

                  <!--Reference the autogenerated SignalR hub script. -->
                  <script src="/signalr/hubs" type="text/javascript"></script>
                  <script>
                      $(document).ready(function () {
                          $("#userTable").DataTable();
                      });
                  </script> 
                 <script type="text/javascript">
                $(function () {

                //alert('First inside the hub script');
                //$("#userTable").DataTable();
        // Declare a proxy to reference the hub.
        var notifications = $.connection.messagesHub;

        alert('Second inside the hub script');

        //$.connection.hub.url = "http://localhost:53612/signalr/hubs";

        //registerClientMethods(notifications);

        //debugger;
        // Create a function that the hub can call to broadcast messages.
        notifications.client.updateMessages = function () {
            getAllMessages()

        };

        // Start the connection.
        $.connection.hub.start().done(function () {
            alert("connection started");
            getAllMessages();
        }).fail(function (e) {
            alert(e);
        });

        //// Start Hub
        //$.connection.hub.start({ waitForPageLoad: false }).done(function () {
        //    alert("connection started")
        //    //registerEvents(notifications)
        //    getAllMessages();

        //});
    });

        function getAllMessages() {
            alert('inside the getAllMessages Function');
            var tbl = $('#userdivTable');
            $.ajax({
                url: '/MessagesSend/GetMessages',
                contentType: 'application/html ; charset:utf-8',
                type: 'GET',
                dataType: 'html'
            }).success(function (result) {
                tbl.empty().append(result);
            }).error(function () {

            });
        }

</script>

@}@

nibavsyed commented 7 years ago

I am using Visual studio 2013 MVC5

nibavsyed commented 7 years ago

var notifications = $.connection.messagesHub; the above statement is not executed

wjkhappy14 commented 7 years ago

me too ,the dependency_OnChange not work !

wjkhappy14 commented 7 years ago

https://www.codeproject.com/Articles/883702/Real-Time-Notifications-using-SignalR-and-SQL-Depe