gpt4 book ai didi

javascript - 无法获取未定义或空引用的属性 'signalR'

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:24:20 29 4
gpt4 key购买 nike

我正在尝试此处的 SignalR 介绍示例:http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-getting-started-with-signalr-20

按照示例,按 F5 后出现以下错误:

Unhandled exception at line 17, column 5 inhttp://myServer.com:12269/signalr/hubs

0x800a138f - JavaScript runtimeerror: Unable to get property 'signalR' of undefined or null reference

我是 SignalR 的新手,不太确定从哪里开始。有什么见解吗?

错误的屏幕截图。它是生成的集线器脚本的一部分。

enter image description here

index.html 上的源代码:

<!DOCTYPE html>
<html>
<head>
<title>SignalR Simple Chat</title>
<style type="text/css">
.container {
background-color: #99CCFF;
border: thick solid #808080;
padding: 20px;
margin: 20px;
}
</style>
</head>
<body>
<div class="container">
<input type="text" id="message" />
<input type="button" id="sendmessage" value="Send" />
<input type="hidden" id="displayname" />
<ul id="discussion"></ul>
</div>
<!--Script references. -->
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.6.4.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.1.0.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>
<!--Add script to update the page and send messages.-->
<script type="text/javascript">
$(function () {
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
// Create a function that the hub can call to broadcast messages.
chat.client.broadcastMessage = function (name, message) {
// Html encode display name and message.
var encodedName = $('<div />').text(name).html();
var encodedMsg = $('<div />').text(message).html();
// Add the message to the page.
$('#discussion').append('<li><strong>' + encodedName
+ '</strong>:&nbsp;&nbsp;' + encodedMsg + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
</script>
</body>
</html>

最佳答案

您必须引用 Scripts 文件夹中的适当版本的 JQuery。

关于javascript - 无法获取未定义或空引用的属性 'signalR',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24635583/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com