2017-07-01 109 views
1

好傢伙我收到以下錯誤:如何解決getJSON方法在我的代碼中的錯誤?

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) 

的json的代碼是這樣的:

\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 });

任何幫助將不勝感激!

+0

問題不在客戶端,而是服務器回覆「禁止」。檢查相應文件/文件夾的設置。 – Sirko

回答

3

包含完整版本的JQuery。似乎你正在使用slim版本。可能不包括$.getJSON()函數和其他ajax調用函數。因此錯誤 - Uncaught TypeError: $.getJSON is not a function

所以使用 -

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

head標籤。

相關問題