I'm using Twitter Bootstrap and I'm working on a page that has several tabs that all have carousels in them (each with a ton of images) I've managed to write an AJAX script that pulls the images from a JSON file I've created (for one of the carousels). I'm planning on making similar JSON file for the rest, but what I'm wondering though is there a way to write the AJAX script so that it grabs the id from the HTML so I don't have to make a unique AJX script for each version of the carousel
Here's how my HTML looks for the carousel:
<div id="ShaluCarousel1b" class="carousel slide"><!-- class of slide for animation -->
<div class="carousel-inner" id="carousel1b">
</div><!-- /.carousel-inner -->
</div>
And here's my AJAX script:
<script>
$.ajaxSetup({
error: function(xhr, status, error) {
alert("An AJAX error occured: " +status + "\nError: " +error);
}
});
$.ajax({
url:'json/carousel1b',
type:'GET',
success: function(data){
console.log('grabbing photos');
var totalPictures = data['totalPictures'];
for (var i=0; i<totalPictures; i++) {
console.log("new image");
if(i<1){
console.log("first image");
var d = "<div class='item active'>";
d += "<a href='" +data.pictures[i]['photo'] +"' rel='prettyPhoto'>";
d += "<img src='" +data.pictures[i]['photo'] +"' >";
d += "</a>";
d += "</div>";
$('#carousel1b').append(d);
}
else {
console.log("image" +i);
var d = "<div class='item'>";
d += "<a href='" +data.pictures[i]['photo'] +"' rel='prettyPhoto'>";
d += "<img src='" +data.pictures[i]['photo'] +"' alt=''>";
d += "</a>";
d += "</div>";
$('#carousel1b').append(d);
$("a[rel^='prettyPhoto']").prettyPhoto();
console.log('pp init');
}
}
}
})
</script>
I'm basically wondering if there is a way to pull the id (carousel1b) from the htnl and inject it into the AJAX strip in the "url:'jason/carousel1b and the "$('carousel').append(d)"