我對jQuery
和AJAX很新,所以我很抱歉如果我是愚蠢的。未定義不是函數(AJAX,PHP,jQuery)
我收到我的AJAX jQuery
腳本中的錯誤。 我通過AJAX獲取數據在我的頁面上動態顯示。 JSON
文件返回一個數組,它必須迭代並顯示在每個項目的DIV中。 的JSON
是:
[{"id":1, "user_id":14, "title":"The Title", "thumbnail":"image.jpg", "summary":"summary of post", "content":"content info here", "category":"Graphic Design", "sub_category":"Adobe Photoshop", "views":0, "published":0, "created_at":"2015-04-16 00:09:57", "updated_at":"2015-04-16 00:09:57"}, {and so on...}]
的jQuery
是:
function retrieveTutorials()
{
\t $.ajax({
\t type: "GET",
\t url: "/tutorials/retrieve",
\t dataType: "json",
\t success: function(data){
var tutorial = ('')
$.each(data, function(){
tutorial.append($( '<div class="generatedbox"><img src="images/tutorial_upload/' + this.thumbnail + '" /><h1>' + this.title + '</h1><p>' + this.summary + '</p><p class="date">' + this.created_at + '</p></div>'))
});
$("#generated-content").empty().append(tutorial);
\t \t },
\t \t error: function() {
\t \t \t alert("An error occurred while processing XML file.");
\t \t }
\t });
}
我目前收到的錯誤是 「遺漏的類型錯誤:未定義是不是一個函數」,它指到以下部分
tutorial.append($( '<div class="generatedbox"><img src="images/tutorial_upload/' + this.thumbnail + '" /><h1>' + this.title + '</h1><p>' + this.summary + '</p><p class="date">' + this.created_at + '</p></div>'))
任何想法,我要去的地方錯了嗎? 我已經使用了非常相似的代碼工作正常之前
這個'var tutorial =('')'是什麼意思? –