JQuery issue "TypeError: $.getJSON is not a function"

I've got this piece of code:

$(document).ready(function () { $.getJSON(' 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=""></script> <script src="lib/main.js"></script>
</head>
<body>
</body>
</html>

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

Thanks!

4

5 Answers

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.

Slim version of jquery excludes ajax, animations effects etc

1

Thus happens commonly when migrating codebases from jQuery v1.x+ to v3.0+ as jQuery updated/deprecated/discontinued some of it's API.

I recommend using jQuery Migrate which will address this, along with other issues:

Get it here via CDN:

If using Gulp/Grunt, you can import into your project using

npm install --save jquery jquery-migrate

Github Repository -

Read more about jQuery v3.0+..

1
function cinta(){
$.getJSON(' function (response) { console.log(response); });
}
cinta();
$(document).ready(function () { console.log('yesss');
});

This work for me in python flask

You can also use Fetch with async and await:

async function getData(){ const response = await fetch( ""
); return response.json();
}
getData().then((data) => {
//... your code
})

Live demo

I had the same error with my piece of code,

$.getJson("/foo.json")

The issue was that my function is actually spelled

$.getJSON

NOT $.getJson.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like