does the flag work as it should? put in a couple of alerts...
Code:
var postHandler = function(postsJSON) {
var postsLocated = false;
$.each(postsJSON,function(i,post) {
postsLocated = true;
alert(postsLocated)//should alert true unless there are no more posts
//post url
var postURL = '' + domain + "test.php?ID=" + post.ID;
var id = 'post-' + post.ID;
//create the HTML
$('<div></div>')
.addClass('post')
.attr('id',id)
//generate the HTML
.html('')
.click(function() {
window.location = postURL;
})
//inject into the container
.appendTo($('#posts'))
.hide()
.slideDown(250,function() {
if(i == 0) {
//$.scrollTo($('div#' + id));
}
if(!postsLocated){
alert(postsLocated)//if this alerts false ONLY when there are no more posts, you are on the right track
}
});
OK, I am getting the "true" alert every time I load a set. However I am not getting an alert when when I run to the end of the database.
This is the section of the code that seems to not be working, does it look right?
Code:
if(i == 0) {
//$.scrollTo($('div#' + id));
}
if(!postsLocated){
alert(postsLocated)//if this alerts false ONLY when there are no more posts, you are on the right track
}
});
});
};
hmm... maybe a small miscalculation on where the functions end Try this one:
Code:
var postHandler = function(postsJSON) {
var postsLocated = false;
$.each(postsJSON,function(i,post) {
postsLocated = true;
alert(postsLocated)//should alert true unless there are no more posts
//post url
var postURL = '' + domain + "test.php?ID=" + post.ID;
var id = 'post-' + post.ID;
//create the HTML
$('<div></div>')
.addClass('post')
.attr('id',id)
//generate the HTML
.html('')
.click(function() {
window.location = postURL;
})
//inject into the container
.appendTo($('#posts'))
.hide()
.slideDown(250,function() {
if(i == 0) {
//$.scrollTo($('div#' + id));
}
});
});
if(!postsLocated){
alert(postsLocated)//if this alerts false ONLY when there are no more posts, you are on the right track
}
});
Bookmarks