Uncaught ReferenceError: $ is not defined
Asked Answered
C

8

3

I am trying to reference to jquery library to provide intellisense on another javascript file. But I got error such as "Uncaught ReferenceError: $ is not defined"

/// <reference path="jquery.min.js" />

$(document).ready(function () {
    alert("alert");
});

EDITED

Note: I have only one jquery library. Any other libraries have not been included.

Clypeus answered 23/6, 2011 at 13:20 Comment(5)
Do you have an example page we can look at?Comanchean
If you are talking about getting intellisense running in visual studio you might want to make that clearer. Possibly with a VS tag of some kind (including what version of VS).Williamswilliamsburg
And can you clarify where the actual error message is coming from?Williamswilliamsburg
@Williamswilliamsburg - In my experience intellisense in VS2008 for JavaScript is next to non-existent - If you know how to make it work I'd be very grateful!Olette
@El Ronnoco: I actually had a bunch of links I'd found that I was going to put as an answer til I saw that one had been accepted. :) weblogs.asp.net/scottgu/archive/2008/11/21/… was one of them and would seem to be a good start. :)Williamswilliamsburg
P
4

Javascripts (including jQuery) are loaded with the following syntax:

<script type="text/javascript" src="url_to_your_script" />

Please review your HTML document to ensure that you have a line like that one, and that the src attribute points to the jQuery script's location. You can test it by copying the contents of the src attribute and pasting it in your browser's address bar.

Psychoneurotic answered 23/6, 2011 at 13:35 Comment(5)
From my understanding of the question he is not having problems including teh script but with gettign intellisense running with it (presumably under visual studio). Hopefully this will gain a VS tag if this is the case.Williamswilliamsburg
@Chris: The error message he posted ("Uncaught ReferenceError: $ is not defined") is the definitive error that is received when jQuery is referenced but not included in an HTML document. I think intellisense is a red herring in this case.Psychoneurotic
Fair enough. That does make sense. But the actual question asked "I am trying to reference to jquery library to provide intellisense on another javascript file." does look like he is trying to do intellisense. It is quite possible that this same error is thrown by VS when it attempt to parse javscript files for intellisense and/or error checking.Williamswilliamsburg
And given your answer was just accepted I guess you were right and intellisense really was a whopping red herring. :)Williamswilliamsburg
It is important to note that the ORDER of inclusion of scripts is also crucial. jQuery library MUST be included FIRST before code that references it.Proposition
P
2

As silly as it sounds, make sure that your script tags have a matching ending </script> tag. If you're missing one, it will mess up the loading of any scripts after it.

Putter answered 23/6, 2011 at 13:35 Comment(0)
A
2

mine same problem solved by replacing

<script src="folderOnMyPc/local/jquery.js"> 

with

<script src="http://code.jquery.com/jquery-latest.min.js">  
Aphid answered 23/8, 2012 at 16:42 Comment(0)
T
1

You probably did not included jQuery properly, or use the noConflict mode : http://api.jquery.com/jQuery.noConflict/

Tressietressure answered 23/6, 2011 at 13:22 Comment(0)
M
1

You might use some other libraries that hide the $-function You can use jQuery as a substance to $. In your example:

/// <reference path="jquery.min.js" />

jQuery(document).ready(function () {
    alert("alert");
});

More info of using jQuery with other librarires can be found here.

Macroscopic answered 23/6, 2011 at 13:23 Comment(3)
I downloaded jquery library and I created my js file. Then I wrote the function above and referenced jquery library. Thats what I did. I dont have any other libraries.Noemi
Are you sure jQuery is even loaded properly? Try doing alert(jQuery), it that doesn't work something might be wrong in the way you're including the jQuery library.Scratches
@Barış V. - how did you reference jQuery? If you referenced it with the comment shown, then that's not how you reference js files.Chari
A
0

My problem was solved by swapping of places of links to jquery library and to jquery script. A link to jquery library must be before the link to a script.

Anthropomorphic answered 5/9, 2023 at 18:51 Comment(0)
P
-1

All the .js files must be accessible by the server. Just check the ownership and permission of the file.

Phoebephoebus answered 20/4, 2013 at 21:25 Comment(0)
F
-1

Try to get query from a CDN like,

For other CDNs http://jquery.com/download/

Note: make sure the url's have 'https://' prefix

Fraga answered 14/8, 2014 at 20:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.