代码之家  ›  专栏  ›  技术社区  ›  rplevy

JQuery:$.get不是函数

  •  30
  • rplevy  · 技术社区  · 16 年前

    如果我运行下面的代码,函数$.get似乎丢失了(getJSON和其他函数也丢失了)。但是$本身和其他函数确实存在,所以我知道JQuery正在加载。

    google.load("jquery", "1.3.2");
    
    function _validate(form, rules_file) {
       $.get('/validation_rules.json',function(data) {
         alert("hello")
       })
    } 
    

    谢谢 抢劫

    编辑:以下是一些附加信息:

      <script src="http://www.google.com/jsapi"></script>
      <script>
        google.load("prototype", "1.6");
        google.load("scriptaculous", "1.8");
        google.load("jquery", "1.3.2");
      </script>
      <script>
        jQuery.noConflict(); // prevent conflicts with prototype
      </script>
      <script src="/livepipe/src/livepipe.js"
              type="text/javascript"></script>
      <script src="/livepipe/src/window.js"
              type="text/javascript"></script>
      <script src="/livepipe/src/tabs.js"
              type="text/javascript"></script>
      <script src="/jquery.maskedinput-1.2.2.js"
             type="text/javascript"></script>
    
    4 回复  |  直到 16 年前
        1
  •  21
  •   Christian C. Salvadó    16 年前

    这个 $ jQuery.noConflict 方法。

    $

    您应该在上使用jQuery方法 jQuery 直接全局对象,例如:

    jQuery.get(/* .. */);
    jQuery.getJSON(/* .. */);
    // etc...
    

    或者,如果需要,可以将另一个较短的变量定义为alias:

    var $j = jQuery.noConflict();
    
        2
  •  214
  •   zx485 potemkin    9 年前

    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
    

    给我

    >jQuery.get
    :undefined
    >jQuery.get()
    :VM7130:1 Uncaught TypeError: jQuery.get is not a function
        at <anonymous>:1:8
    

    加载相同的库时,不使用 苗条的

    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    

    效果很好

        3
  •  15
  •   marc_s MisterSmith    7 年前

    一般来说,当你有 $.get is not a function

        4
  •  3
  •   moranjk    15 年前

    您还可以将jQuery函数包装在闭包中,并将jQuery作为“$”符号传入,例如:

    (function($) {
        function _validate(form, rules_file) {
           $.get('/validation_rules.json',function(data) {
           alert("hello")
           })
        }
    })(jQuery)
    
        5
  •  2
  •   Chandra Patni    16 年前

    如果指定jQuery.noConflict(),则$不再可用于jQuery。改用jQuery.get。

        6
  •  0
  •   Shadi Alnamrouti    5 年前

    我没有包括JQuery脚本 . 这是修复方法:

    <head>    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    </head>