【发布时间】:2015-04-16 01:57:50
【问题描述】:
我对@987654321@ 和 AJAX 很陌生,所以如果我很愚蠢,我深表歉意。
我的 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()
{
$.ajax({
type: "GET",
url: "/tutorials/retrieve",
dataType: "json",
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);
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
}
我目前收到的错误是“Uncaught TypeError: undefined is not a 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>'))
关于我哪里出错了有什么想法吗? 我之前使用过非常相似的代码,效果很好
【问题讨论】:
-
这个
var tutorial = ('')是什么意思?
标签: javascript php jquery ajax json