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?

Answers


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)


Try like this, Get the innerHTML of your target div and add all the element to that div and finally add the innerHTML to created HTML string

 HTML = document.getElementById('notizie').innerHTML;
 $(news).each(function (item) {
      HTML += "<div class=\"item container\"></div>";
      HTML += "<h4>" + news[item].Title + "</h4>";
      HTML += "<p>" + news[item].Text + "</p>";
      HTML += "<div class=\"post\"></div>";
 });
document.getElementById('notizie').innerHTML = HTML;

Need Your Help

Can we launch navigation drawer without using ActionBarDrawerToggle?

android navigation android-actionbar drawer

Can we launch navigation drawer without using ActionBarDrawerToggle? In my implementation, I do not want to use action bar.

Unless I start Management Studio with "Run as administrator", I get a Login Failure (Error 18456)

.net sql-server windows-7 ssms

I cannot connect to the SQL Server instance if I do not start management studio as a administrator. I am running windows 7, SQL Server 2008, and Management Studio 10.0. If I run as a normal user,...