Javascript JQuery 错误:未捕获的类型错误:对象 #<HTMLDocument> 没有方法“就绪”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5706093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:32:01  来源:igfitidea点击:

JQuery Error: Uncaught TypeError: Object #<HTMLDocument> has no method 'ready'

javascriptjquerywordpress

提问by zeemy23

my site is getting the error in this title in the javascript console. Google seems to say that it is because jquery isn't loaded, but it is definitely visible in the head.

我的网站在 javascript 控制台中收到此标题中的错误。google好像说是jquery没有加载的缘故,但是脑袋里肯定是看得见的。

<script type="text/javascript">
  $(document).ready(function(){
    $.ajax({
      type: "GET",
      url: "https://www.mjfreeway.com/naturalremedies/mml-connect/45.xml",
      dataType: "xml",
      success: function(xml) {
        $(xml).find("products").each(function() {
          $(this).find("product").each(function() {
            $("#output").append($(this).find("title").text() + "<br />");
          });
        });
      }
    });
  });
</script>

the site is medical marijuana related, so nsfw for some.sorry for the messy head, it's in dev mode. http://www.kindreviews.com/1/mmc/

该网站与医用大麻有关,所以 nsfw 为某些人。抱歉,头很乱,它处于开发模式。 http://www.kindreviews.com/1/mmc/

Thanks, zeem

谢谢,泽姆

回答by brandizzi

Apparently you are using both jQuery and Mootools and both of them do use $as an alias to a core function. Probably the $function which is generating this error is the Mootools function. I'd suggest you to try to write your jQuery code using jQueryinstead of $so you can confirm my point is right or not.

显然,您同时使用 jQuery 和 Mootools,并且它们都$用作核心函数的别名。可能$产生此错误的函数是 Mootools 函数。我建议您尝试使用jQuery而不是编写您的 jQuery 代码,$以便您可以确认我的观点是否正确。

Good luck!

祝你好运!

回答by tbthorpe

Yup - I believe that's exactly the problem. jQuery and mooTools fight over the use of the $ notation.

是的 - 我相信这正是问题所在。jQuery 和 mooTools 为 $ 符号的使用而争论不休。

You're on the right track with using

你在正确的轨道上使用

try{
   jQuery.noConflict();
 } catch(e){};

But after you use that, in order to use jQuery functionality, you have to call it jQuery(...) instead of $(...). Example:

但是在您使用它之后,为了使用 jQuery 功能,您必须将其称为 jQuery(...) 而不是 $(...)。例子:

// Use jQuery via jQuery(...)
 jQuery(document).ready(function(){
   jQuery("div").hide();
 });

Here's a link to the jQuery docs regarding this: http://docs.jquery.com/Using_jQuery_with_Other_Libraries

这是关于此的 jQuery 文档的链接:http: //docs.jquery.com/Using_jQuery_with_Other_Libraries

回答by Daj Shung

I had the same error when I forgot to add the header-line:

当我忘记添加标题行时,我遇到了同样的错误:

<script type="text/javascript" src="/javascript/jquery-ui-1.8.14.custom.min.js">   
</script>