How to let the loop separate on Row

Asked

Viewed 46 times

-1

Good night, basically I need to get one. json and loop it to pick up all the tables with the title name, but when doing so it returns me all together and can not set apart to put inside a table.

$("#button").click(function() 
{
    var url = "http://localhost/log.json";

    $.getJSON(url).done(function(data)
    {
        var title = "";
        var i;

        for (i = 0; i <= data.length; i++) 
        {
            title += data[i].title ;
            $("#nome").text(title);     
        }
    });
});

    <table class="table">
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td id="nome"></td>
          </tr>
        </tbody>
      </table>

inserir a descrição da imagem aqui

Well if I’m not clear, I want each name inside a (table) and not all together like this now! , The titles were withdrawn by scraper I made in xvideos

Thanks if anyone can help!!

1 answer

0


Here’s a perfect example for your case. It’s in the documentation of jQuery.

JavaScript:

$.getJSON( "ajax/test.json", function( data ) {
  var items = [];
  $.each( data, function( key, val ) {
    items.push( "<li id='" + key + "'>" + val + "</li>" );
  });

  $( "<ul/>", {
    "class": "my-new-list",
    html: items.join( "" )
  }).appendTo( "body" );
});

And a JSON super simple, just for the example of code:

{
  "one": "Singular sensation",
  "two": "Beady little eyes",
  "three": "Little birds pitch by my doorstep"
}

Here is the link to deepen your studies: https://api.jquery.com/jquery.getjson/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.