Skip to content
Advertisement

JQuery issue “TypeError: $.getJSON is not a function”

I’ve got this piece of code:

$(document).ready(function () {
    $.getJSON('http://localhost:5000/', function (response) {
        console.log(response);
    });
});

localhost:5000 is a flask/python script that returns a json like:

{
  "data": [
    0, 
    0, 
    0, 

And I’m getting:

$.getJSON is not a function TypeError: $.getJSON is not a function

Any tips where I can start untangling the whoolball?

Thanks!

Edit:

HTML:

<!DOCTYPE html>
<html>

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

<body>
</body>

</html>

lib/main.js is where the document.ready is located.

Thanks!

Advertisement

Answer

You seem to be using slim version of jquery which does not have the method getJSON thats why you are getting this error.

Please use the full version of jquery instead from the below link.

https://code.jquery.com/jquery-3.1.1.min.js

Slim version of jquery excludes ajax, animations effects etc

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement