我对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 =('')'是什么意思? –