【发布时间】:2014-10-03 15:15:36
【问题描述】:
我目前在使用网络浏览器调试客户端代码时遇到以下错误:
TypeError: $ is undefined
ReferenceError: $ is not defined
在调试器的“网络”选项卡中,它将 JQueries 脚本显示为“404”。这是否表明我的 Jqueries 没有被渲染/初始化
这是我的客户端代码:
<script src="Scripts/jquery-1.10.2.min.js"></script>
<script src="Scripts/jquery.signalR-2.1.0.min.js"></script>
<script src='<%: ResolveClientUrl("~/signalr/hubs") %>'></script>
<script type="text/javascript">
$(function () {
// Declare a proxy to reference the hub.
var notifications = $.connection.NotificationHub;
// Create a function that the hub can call to broadcast messages.
notifications.client.recieveNotification = function (role, descrip) {
// Add the message to the page.
$('#spanNewMessages').text(role);
$('#spanNewCircles').text(descrip);
};
// Start the connection.
$.connection.hub.start().done(function () {
alert("Preparing to send notifications...");
notifications.server.sendNotifications();
alert("Notifications have been sent.");
}).fail(function (e) {
alert(e);
});
//$.connection.hub.start();
});
</script>
<h1>New Notifications</h1>
<div>
New <span id="spanNewMessages"></span> role.<br />
New<span id="spanNewCircles"></span> descrip.<br />
</div>
更新的 Jquery 脚本:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script src="~/Scripts/jquery.signalR-2.1.0.min.js"></script>
<script src='<%: ResolveClientUrl("~/signalr/hubs") %>'></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
任何帮助都会非常有帮助。谢谢
【问题讨论】:
-
"在调试器的“网络”选项卡中,它显示 JQueries 脚本为“404”。这是否表明我的 Jqueries 没有被渲染/初始化” - 是的。脚本路径不正确。
标签: javascript c# jquery asp.net signalr