JavaScript runtime error: "$" - undefined

Such a classic problem, but with terrible time finding the actual cause. Usually, when I see this error, because the jQuery link after the code requiring it, or the jQuery backlink, or the jQuery conflict, etc., so far none of them look like this. Unfortunately, the search for a solution to this problem made me publish a post after such cases. I’m sure that my problem here is equally simple, but I’ve been unlucky in an hour of hunting ...

Edit: Additional information ... The solution file (which I tried to recreate several times, trying to figure it out. It is a JavaScript template for the Windows Store Blank, and I do it in Visual Studio. The only link files are the Windows library for javascript 1.0, I tried to delete This is also for verification.

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>HTML5 Canvas Template</title> <style> /* styles here */ </style> </head> <body> <canvas id="myCanvas" width="500" height="500"> <p>Canvas not supported.</p> </canvas> <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { var canvas = $("#myCanvas").get(0); var context = canvas.getContext("2d"); function renderContent() { // we'll do our drawing here... } renderContent(); }); </script> </body> </html> 
+8
javascript jquery html5 canvas
source share
6 answers

It states that the JQuery link is incorrect

Try the following:

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
+11
source share

In my case, the problem was that I was displaying my page on https, but I was trying to request a JQuery file on http, which was blocked by many browsers for security reasons.

My fix was to change this ...

 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 

... to that...

 <script src="//code.jquery.com/jquery-1.9.1.min.js"></script> 

This forces the browser to load jQuery using the same protocol (http or https) as the displayed page.

+1
source share

I tried all of the above and nothing works until I put this line

 <script src="../scripts/jquery-2.2.3.min.js" type="text/javascript"></script> 

in the header section of the HTML file. So here is what it looks like:

 <!DOCTYPE html> <html> <head> <!-- jQuery Reference --> <script src="../scripts/jquery-2.2.3.min.js" type="text/javascript"></script> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <title>some title</title> </head> <body> ... 

And the js file is at a lower level in the "scripts" folder. Finally, the error has disappeared and what a relief!

+1
source share

Anover option, in my case - I was forced to use a proxy. So - IE11 β†’ InternetOptions β†’ Connections β†’ LANSettings-Proxy Server β†’ UseProxyServer - should be checked. Also check the availability of the jquery script source, my processed version in VS2012 - exactly as in the above example

0
source share

Some of my clients had this problem, because, apparently, they blocked the loading of Javascript from third-party sites. So now I always use the following code to enable jQuery:

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> window.jQuery || document.write('<script type="text/javascript" src="/js/jquery-1.9.1.min.js">\x3C/script>') </script> 

This ensures that even if my client blocks the loading of the Javascript file from the CDN domain, the client still downloads the file from my own server, which is not blocked by the browser.

0
source share

I was getting the same error code:

(Error: "generateText" - undefined)

... in code

var bodyText=["The....now."]

I found in my text editor (Notepad ++) when entering many lines of text directly above the bodyText variable, if I didn’t hit return carriage (enter ==> WordWrap is turned off) I just saved typing w / o return carriage and let the editor adjust the text, with whom did he work?

Should it be in the settings Notepad ++ ??

-one
source share

All Articles