[RESOLVED]Jquery Type-error

I am currently experiencing the following errors, while debugging my client-side code using web-browser:

TypeError: $ is undefined 
ReferenceError: $ is not defined

In the in the "Network" tab, of the debugger, it shows the JQueries scripts as "404". Does this indicate my Jqueries are not being render/initialized

This is my client-side code:

<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>

Any help would be very helpful.  Thank you

Are you sure that the name of your jQuery file matches the one that you are referencing exactly?

You might try one of the following approaches :

  • Try dragging your actual jQuery file from your Scripts folder into the mark-up for your page (this should automatically add the reference which should be correct) :
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
  • Alternatively, you can use the ResolveUrl() method (assuming your are using Web Forms) which functions similar to the ResolveClientUrl() method you are currently calling. This will accept a relative path and resolve the appropriate absolute path for it
    :

    <script src="<%= ResolveUrl("~/Scripts/jquery-1.10.2.min.js") %>"></script>

If you are still encountering issues, you might also try using the Developer Tools (F12) within your browser to see if any other errors are present within the Console.

Thank you for your suggestions, as they helped me solved 404 error. Many thanks :)

Leave a Reply