[英]SignalR client undefined
我在这个前端代码中进行了表的更新,因为很快在sql表中更新了。 但我找不到解决这个问题的方法。
未捕获的TypeError:无法读取未定义的属性“client”
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery.signalR-2.0.2.min.js"></script>
<script src="signalr/hubs"></script>
<script>
$(function () {
// Proxy created on the fly
var job = $.connection.DataHub;
console.log(job);
// 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 = $('#tblJobInfo');
$.ajax({
url: '../api/values',
type: 'GET',
datatype: 'json',
success: function (data) {
if (data.length > 0) {
$tbl.empty();
$tbl.append(' <tr><th>ID</th><th>Titulo</th>/tr>');
var rows = [];
for (var i = 0; i < data.length; i++) {
rows.push(' <tr><td>' + data[i].Id + '</td><td>' + data[i].titulo + '</td></tr>');
}
$tbl.append(rows.join(''));
}
}
});
}
</script>
怎么解决这个问题?
我想问题是你没有将集线器的名称更改为驼峰的情况。 见下文:
var job = $.connection.dataHub;
如果使用HubName属性,则JavaScript客户端上的camel case不会更改名称:
[HubName("DataHub")]
public class DataHub: Hub
此外,如果您使用的是ASP.NET MVC 4或5 Razor视图,请使用代字号来引用代理文件引用中的应用程序根目录:
<script src="~/signalr/hubs"></script>
我们得到了同样的错误但是,在我们的例子中,我们在Windows Server 2008 IIS 7上有一个部署(并且它没有错误)和另一个(相同的应用程序,相同的代码)在Windows Server IIS 8上(引发了与原始海报)。
我们的解决方案是在IIS 8上部署时修改web.config并注释信号器/集线器的位置部分中的“system.webServer”部分。
(注意system.webServer被评论)
<location path="signalr/hubs">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
<!--system.webServer>
<security>
<authorization>
<add accessType="Allow" users="*"/>
</authorization>
</security>
</system.webServer-->
</location>
这是原始的,它适用于IIS 7,但在IIS 8上失败:
(注意system.webServer未注释)
<location path="signalr/hubs">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
<system.webServer>
<security>
<authorization>
<add accessType="Allow" users="*"/>
</authorization>
</security>
</system.webServer>
</location>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.