As a disclaimer, I'm a scavenger / hacker of jQuery and not a proficient developer thereof.
I'm attempting to build Twitter-esque pagination, which is almost working.
I'm using PHP & MySQL to retrieve data in JSON format, which is arriving to me as:
[
{
"bookmark_id":"5507",
"creation":"Mon 16th Jul 2012",
"url":"http:\/\/www.bbc.co.uk\/news\/science-environment-18833386",
"title":"Light trick to see around corners ..."
}
...
]
The code itself is:
<script type="text/javascript">
function paginate(limit) {
if (limit == 0) { count = 0; } else if (limit > 0) { count += 10; }
$(".flash").show();
$(".flash").fadeIn(400).html("Loading...");
var data = "limit=" + count;
$.ajax({
type: "POST",
url: "<?php echo config_item('base_url'); ?>topics/jq_get_bookmarks_for_topic_by_tag_as_object/" + <?php echo $results['select_topic'][0]['topic_id']; ?>,
data: data,
cache: false,
success: function **(index, element)** {
alert(index);
$(".flash").hide();
$(".load-link").addClass("link-none");
for (var i=0;i<element.length;i++) {
$("#data-topics-bookmarks-tags").append('<tr><td>[<a href="<?php echo config_item('base_url'); ?>bookmarks/view/' + **element.bookmark_id** + '">View</a>] [<a href="<?php echo config_item('base_url'); ?>bookmarks/visit/' + element.bookmark_id + '" target="_blank">Link</a>] <a href="<?php echo config_item('base_url'); ?>bookmarks/edit/' + element.bookmark_id + '" title="Edit ' + element.title + '">‘' + element.title + '’</a></td><td>' + element.creation + '</td></tr>');
}
}
}
);
}
paginate("0");
</script>
And the link that triggers the loading of more data is:
<p><a href="#load" onclick="paginate('10')">Load Bookmarks</a></p>
Everything is working .. with the obvious exception of me actually being able to access the data and have it display as anything other than "undefined".
I've tried every combination I can think of in the two areas I've marked as bold.
When I click the load link, it appends the table as expected, but every item is "undefined".
And yes, the data is coming through as described above; I took the data from an alert(index).
I'm sure this is a simple fix for the proficient among us, but I'm not among them.