gpt4 book ai didi

javascript - 未定义不是函数(AJAX、PHP、jQuery)

转载 作者:行者123 更新时间:2023-11-28 13:25:22 25 4
gpt4 key购买 nike

我对 jQuery 和 AJAX 很陌生,所以如果我很愚蠢,我深表歉意。

我的 AJAX jQuery 脚本中收到错误。我正在通过 AJAX get 检索数据以动态显示在我的页面上。JSON 文件返回一个数组,必须迭代该数组并将其显示在每个项目的 DIV 中。JSON 是:

[{"id":1,
“用户id”:14,
"title":"标题",
"thumbnail":"图片.jpg",
"summary":"帖子摘要",
"content":"此处内容信息",
"category":"平面设计",
"sub_category":"Adobe Photoshop",
“观看次数”:0,
“已发布”:0,
"created_at":"2015-04-16 00:09:57",
"updated_at":"2015-04-16 00:09:57"},{等等...}]

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.");
}
});
}

我当前收到的错误是“未捕获的类型错误:未定义不是函数”,它引用了以下部分

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 = $('<div></div>');

关于javascript - 未定义不是函数(AJAX、PHP、jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29664073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com