Javascript 如何使用jQueryAjax将JSON目标分部分加载?
我想知道如何使用jQueryAjax显示JSON对象的前五项,如果单击按钮Javascript 如何使用jQueryAjax将JSON目标分部分加载?,javascript,jquery,json,ajax,Javascript,Jquery,Json,Ajax,我想知道如何使用jQueryAjax显示JSON对象的前五项,如果单击按钮#load,每次会有5项加载。如果没有if(我的第一步是在每次单击时停止发送ajax请求,因为在第一次单击后您已经获得了所需的所有数据。您可以覆盖(var i=0;i
#load
,每次会有5项加载。如果没有if(我的第一步是在每次单击时停止发送ajax请求,因为在第一次单击后您已经获得了所需的所有数据。您可以覆盖(var i=0;i)
从0到4,而不是遍历AJAX数组的长度。但是,正如Kevin所指出的,由于您已经检索到了所有数据,所以这里没有其他事情可做。如果您有检索数据的服务,您可以传递一个lastItemReceived
,从特定索引开始……因此使用此设置是不可能的?将它们全部放在dom中,并将loadMore
看作是简单的showMore
。否则,修改后端以仅发送所需内容,并跟踪已发送的内容
$.ajax({
url: 'api/videoData.js',
dataType: 'json',
success: function(data) {
// console.log(data); //uncomment this for debug
// root.dataArr = data;
Triptube.dataController.timelineEvents(data);
var index = 0;
var loadmore = false;
var el = $('.featured'); // .featured
$.get('directives/format-text.html', function(response){
console.log('succes');
})
.done(function (response) {
// console.dir(response);
var raw_model = response;
for (var i = 0; i < raw_model.length; i++) {
if (i <= 4) {
model = $(raw_model);
model.find('h4').html(data.content[i].subtitle);
model.find('h3').html(data.content[i].title);
model.find('p').html(data.content[i].text);
$('.featured').append(model);
}
if (loadmore) {
console.log('Clicked');
loadmore = false;
}
}
$('#loadmore').click(function(e) {
e.preventDefault();
loadmore = true;
});
})
.fail(function (response) {
console.dir(response);
});
},
error: function(data) {
console.log(data);
console.log('Houston, we have a problem!');
}
});
{
"title": "London",
"category": "The Ultimate",
"image": "images/content/londen.jpg",
"website": "http://www.london.nl/",
"youtube": "https://www.youtube.com/watch?v=Sq9rjbouBlY&t=23",
"maps": "https://www.google.nl/maps/place/Londen,+Verenigd+Koninkrijk/@51.5114089,-0.1271477,13.79z/data=!4m2!3m1!1s0x47d8a00baf21de75:0x52963a5addd52a99",
"content": [
{
"type" : "normal",
"timeTrigger": 24,
"title": "London Eye",
"subtitle": "Algemene",
"picture" : "images/content/london.jpg",
"text": "This is the London Eye",
"readmore": "http://wikitravel.org/en/London"
},{
"type": "normal",
"timeTrigger": 24,
"title": "Sherlock Holmes",
"subtitle": "Detective",
"picture" : "images/content/sherlock_holmes.jpg",
"text": "Sherlock Holmes is een fictieve detective <br> uit de verhalen van de laat-19de-eeuwse",
"readmore": "http://nl.wikipedia.org/wiki/Sherlock_Holmes"
},{
"type": "normal",
"timeTrigger": 39,
"title": "Fish \"n Chips",
"subtitle": "Eten",
"picture" : "images/content/sherlock_holmes.jpg",
"text": "Fish and chips is een typisch Britse afhaalmaaltijd .",
"readmore": "http://youngandfoodish.com/london/top-10-fish-and-chips-in-london/"
}
]
}