I am trying to iterate through a JSON response object to create a list of Category Items. I am trying to assign the unique Category ID value to each hyperlink so that when a user clicks on the hyperlink they will go to a page 2 and the page will then filter based on the selected Category Id. I am stuck on a logic error in my FOR LOOP where all of the Category Ids are being assigned to the one hyperlink. Also, is there a better way to pass data between HTML pages?
$(document).ready(function() {
$.ajax({
url: "https://api.coursera.org/api/catalog.v1/categories",
type: 'GET',
dataType: "json",
success: function(data) {
//alert(data.elements.length);
for(var i = 0; i < data.elements.length; i++)
{
$("#courseLink").append("<a href='page2.html?CatId="+data.elements[i].id+"'>"+data.elements[i].name+"</a><br/>");
$("#courseLink").click(function() {
$("#test").append("work");
});
}
}
});
});