JavaScript runtime error: '$' is undefined

匿名 (未验证) 提交于 2019-12-03 01:06:02

问题:

So classic problem, but having a horrible time on finding the actual cause. Typically when I see this error it's because the jQuery reference is after code requiring it, or back jQuery link, or jQuery conflict, etc... so far none of those appear to be the case. Unfortunately seeking out the solution to this problem has lead me to post after post of such cases. I'm sure my problem here is equally as simple, but over an hour of hunting, still no luck...

Edit: Additional information... The solution file (which I've recreated multiple times trying to figure this out. Is a JavaScript Windows Store Blank App template and I'm doing this in Visual studio. The only references files is Windows Library for javascript 1.0, I have tried deleting this to test as well.

               HTML5 Canvas Template

Canvas not supported.

回答1:

It's states that JQuery referred URL is not correct

Try this:



回答2:

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

My fix was to change this...

...to this...

This causes the browser to download JQuery using the same protocol (http or https) as the page being rendered.



回答3:

I tried everything listed above and nothing seems to work until I put this string

in the head section of the HTML file. So here's how it looks:

             some title ... 

And the js file is located at a level below in the folder 'scripts'. Finally, the error is gone and what a relief!



回答4:

Anover variant, in my case - I was forced to use proxy. So - IE11--> InternetOptions --> Connections-->LANSettings-Proxy Server--> UseProxyServer - should be checked. Also check awailability of jQUery script source, my worked variant in VS2012 - -just like in top example



回答5:

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

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



回答6:

I was getting this same error code:

(Error: 'generateText' is undefined)

...on the code

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

I discovered on my text-editor(Notepad++), when typing many lines of text in the directly above the variable bodyText, if I didn't hit return carriage (enter==>WordWrap is off) just kept typing w/o return carriage and let the editor adjust text it worked?

Must be in the settings of Notepad++??



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!