I have a lot of new things for JavaScript. I am trying to implement a simple SignalR server callback in JavaScript.
First, _Layout.cshtml
<body>
<div class="container body-content">
@RenderBody()
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
Next is my index.html
<body>
@section scripts
{
<script src="/Scripts/jquery-3.1.1.min.js"></script>
<script src="/Scripts/jquery.signalR-2.1.2.js"></script>
<script src="/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
console.log("HELLO WORLD");
$.connection.hub.url = 'http://blah:8094/signalr';
var proxy = $.connection.DashboardHub;
proxy.client.NotifyAllClientsOfChanges = function () {
var searchUrl = "Home/GetData";
$.ajax({
url: searchUrl,
type: "POST",
success: function (data) {
$("#divData").html(data);
}
});
};
$.connection.hub.start({ transport: 'auto', xdomain: true })
.done(function () {
console.log('Connected.');
})
.fail(function (e) {
console.log('Unable to connect:' + e);
});
});
</script>
}
@using (@Html.BeginForm("Index", "Home"))
{
<div id="divData">
@{
var grid = new WebGrid(Model);
@grid.GetHtml(
mode: WebGridPagerModes.All,
columns:
grid.Columns
(
grid.Column(columnName: "SiteId", header: "Site Id", format: @<text>@item.SiteId</text>),
grid.Column(columnName: "Instrument", header: "Instrument", format: @<text>@item.InstrumentId</text> ),
.
.
.
))
}
</div>
}
</body>
I see the “HELLO WORLD” console log at the top, but I do not see any of the console logs for “Connected” or “Unable to connect”
I see an error in the console saying: "Unable to read property" client "undefined"
I followed many SO posts on similar topics and tried many things. I'm not quite sure if this is correctly encoded.
Does anyone see what is wrong?
thank
source
share