JQuery: $.get is not a function

JavascriptJquery

Javascript Problem Overview


I'm having a problem doing something very basic in jQuery. Can someone tell me what I'm doing wrong exactly?

If I run the code below, the function $.get seems to be missing (getJSON and others missing too). But $ itself and other functions do exist, so I know JQuery is loading.

google.load("jquery", "1.3.2");

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

Any ideas would be much appreciated.

Thanks, Rob

Edit: here is some additional info:

  <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>

Javascript Solutions


Solution 1 - Javascript

This will happen, too, if you use the SLIM version of jQuery.

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

gave me

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

while loading the same library without the slim option

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

works well

>jQuery.get() :Object {readyState: 1}

Solution 2 - Javascript

The $ variable you have is from Prototype-js, because you are using the jQuery.noConflict method.

That method will restore the $ variable back to whichever library first implemented it.

You should use the jQuery methods on the jQuery global object directly, eg.:

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

Or you can define another shorter variable as alias if you want:

var $j = jQuery.noConflict();

Solution 3 - Javascript

Generally speaking, when you are having the $.get is not a function error be sure you are not using the slim version of jQuery coming from Bootstrap original imports.

Solution 4 - Javascript

You can also wrap your jQuery functions in a closure and pass in jQuery as the "$" sign, eg.:

(function($) {
    function _validate(form, rules_file) {
       $.get('/validation_rules.json',function(data) {
       alert("hello")
       })
    }
})(jQuery)

Solution 5 - Javascript

If you specify jQuery.noConflict(), then $ is no longer available from jQuery. use jQuery.get instead.

Solution 6 - Javascript

For me I wasn't including JQuery script. This is the fix:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrplevyView Question on Stackoverflow
Solution 1 - JavascriptChrisView Answer on Stackoverflow
Solution 2 - JavascriptChristian C. SalvadóView Answer on Stackoverflow
Solution 3 - JavascriptSamuel RIGAUDView Answer on Stackoverflow
Solution 4 - JavascriptmoranjkView Answer on Stackoverflow
Solution 5 - JavascriptChandra PatniView Answer on Stackoverflow
Solution 6 - JavascriptShadi NamroutiView Answer on Stackoverflow