gpt4 book ai didi

javascript - 下一个和上一个按钮中的 Json 数据

转载 作者:行者123 更新时间:2023-12-02 17:42:18 25 4
gpt4 key购买 nike

单击下一个和上一个按钮后,我必须使用 AJAX 调用来获取 Json 数据。 Json 数据应包含单击下一个或上一个后显示的博客内容。我的函数应该是什么样子有什么建议吗?到目前为止我只有:

function getPrev() {
$.ajax({
type: "GET",
url: "../Content/test.txt",
dataType: "json"
}).success(function (data) {
$.each(data, function (key, val) {
$('#blogcont').append(key+ val);
});
return false;
});
}

而我的 Json 文件只是一个测试文件:

   {"one":"test1", "two":"test2", "three":"test3" }

对不起,我是初学者!!!!谢谢

最佳答案

您的 $.ajax() 语法不正确

function getPrev() {
$.ajax({
type: "GET",
url: "../Content/test.txt",
dataType: "json",
success: function(data) {
var content = "";
$.each(data, function(key, val) {
content += "<p>" + key + ":" + val + "</p>";
});
$('#blogcont').html(content);
}
});
return false;
}

function getPrev() {
$.ajax({
type: "GET",
url: "../Content/test.txt",
dataType: "json"
}).done(function(data) {
var content = "";
$.each(data, function(key, val) {
content += "<p>" + key + ":" + val + "</p>";
});
$('#blogcont').html(content);
});
return false;
}

试试这个

function getPrev() {
$.ajax({
type: "GET",
url: "../Content/test.txt",
dataType: "json"
}).done(function(data) {
var content = "";
$.each(data, function(key, val) {
content += '<p>' + key + ':' + val + '</p>';
});
$('#blogcont').html(content)
.find('p')
.hide()
.first().show();
$('button.next').click(function() {
$('#blogcont').find('p:visible')
.hide()
.next('p').show();
});


});
return false;
}

关于javascript - 下一个和上一个按钮中的 Json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22095720/

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