vivek gupta
vivek gupta

Reputation: 113

how to fix getJSON method error in my code?

hello guys i am getting the following errors :

Failed to load resource: the server responded with a status of 403 (Forbidden)
jquery-3.1.1.slim.min.js:2 jQuery.Deferred exception: $.getJSON is not a function TypeError: $.getJSON is not a function
    at HTMLDocument.<anonymous> (http://localhost/whatever/js/super.js:15:4)
    at j (https://code.jquery.com/jquery-3.1.1.slim.min.js:2:30164)
    at k (https://code.jquery.com/jquery-3.1.1.slim.min.js:2:30478) undefined
r.Deferred.exceptionHook @ jquery-3.1.1.slim.min.js:2
jquery-3.1.1.slim.min.js:2 Uncaught TypeError: $.getJSON is not a function
    at HTMLDocument.<anonymous> (super.js:15)
    at j (jquery-3.1.1.slim.min.js:2)
    at k (jquery-3.1.1.slim.min.js:2)

my json code is this :

	$.getJSON('../whatever/data/comments.json',	function (data) {
		var commentStr = '<ul class="list-unstyled">';
		$.each(data , function (i ,item) {
			// body...
			commentStr += '<li class="media my-4">';
			commentStr += '<img class="d-flex mr-3" src="..." alt="Generic placeholder image">';
			commentStr += '<div class="media-body">';
			commentStr += '<h5 class="mt-0 mb-1">'+ item.name +'</h5>';
			commentStr += '' + item.comment + '</div></li>';
		});
		$("#comment").html("commentStr");
	});

Any help will be appreciated!

Upvotes: 1

Views: 2764

Answers (1)

pro_cheats
pro_cheats

Reputation: 1582

Include full version of JQuery. Seems like you are using a slim version. Probably that doesn't include $.getJSON() function and other ajax call functions. Hence the Error - Uncaught TypeError: $.getJSON is not a function.

So use -

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

in your head tag.

Upvotes: 4

Related Questions