2017-07-01 1 views
1

Hallo Jungs, ich die folgenden Fehler bin immer:Wie behebe ich getJSON-Methodenfehler in meinem Code?

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) 

mein json Code ist dies:

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

Jede Hilfe wird geschätzt!

+0

Das Problem ist nicht auf der Client-Seite, aber der Server antwortet mit "verboten". Überprüfen Sie Ihre Einstellungen für die jeweilige Datei/den Ordner. – Sirko

Antwort

3

Schließen Sie die vollständige Version von JQuery ein. Es scheint, als ob Sie eine slim Version verwenden. Wahrscheinlich enthält das nicht $.getJSON() Funktion und andere ajax Call-Funktionen. Daher der Fehler - Uncaught TypeError: $.getJSON is not a function.

So verwenden -

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

in Ihrem head-Tag.

Verwandte Themen