Michele Boscagin Michele Boscagin - 2 months ago 17
ASP.NET (C#) Question

Wrong bind on aspx from jquery

Got a problem with bind some data on a bootstrap carousel. Data set perfectly, but the bind on HTML fail.
Here the jQuery snippet:

function OnSuccessNews(response) {
var news = response.d;
$(news).each(function (item) {
$("#notizie").append("<div class=\"item container\">");
$("#notizie").append("<h4>" + news[item].Title + "</h4>");
$("#notizie").append("<p>" + news[item].Text + "</p>");
$("#notizie").append("<div class=\"post\"></div>");
$("#notizie").append("</div>");
});
$('.item').first().addClass('active');
$('#carouselNews').carousel();
}



Then the aspx page:

<div class="row">
<div class="col-md-12">
<div class="carousel slide" id="carouselNews">
<div class="carousel-inner" id="notizie"></div>
</div>
</div>
</div>



The problem is: I must to bind some news (with a title and text) in the bootstrap carousel, cycle endless the news in couple.
Now this code show me all the data in news and no cycle. How to display 2 news a time and cycle the next news?

Answer

do it like this :

function OnSuccessNews(response) {
var news = response.d;
$(news).each(function (item) {
    var container = $("<div class=\"item container\"></div>");

    container.append("<h4>" + news[item].Title + "</h4>");
    container.append("<p>" + news[item].Text + "</p>");
    container.append("<div class=\"post\"></div>");
    $("#notizie").append(container);
});
$('.item').first().addClass('active');
$('#carouselNews').carousel();
}

create a container and put data inside the container and append it to $("#notizie)

Comments