Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: $.get is not a function

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> 
like image 741
rplevy Avatar asked Dec 24 '09 04:12

rplevy


People also ask

Is not a function in jQuery?

on if not a function" jQuery error occurs for 2 main reasons: Loading an old version of the jQuery library that doesn't support the on function. Loading a library that overrides the value of the dollar sign $ variable.

What is get in jQuery?

Description. The jQuery. get( url, [data], [callback], [type] ) method loads data from the server using a GET HTTP request. The method returns XMLHttpRequest object.

What is not a function?

A function is a relation in which each input has only one output. In the relation , y is a function of x, because for each input x (1, 2, 3, or 0), there is only one output y. x is not a function of y, because the input y = 3 has multiple outputs: x = 1 and x = 2.


2 Answers

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}

like image 131
Chris Avatar answered Sep 18 '22 15:09

Chris


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(); 
like image 31
Christian C. Salvadó Avatar answered Sep 19 '22 15:09

Christian C. Salvadó