New rows from HTML

New rows from HTML

Kossin17Kossin17 Posts: 3Questions: 2Answers: 0

Hello!

I send ajax request, he is back HTML

<tr>                  
          <td>2017/11/08</td>
          <td>Ваш человек <strong>первой</strong>оплатил</td>
           <td>600</td>
</tr>
<tr>                  
          <td>2017/11/08</td>
          <td>Ваш человек <strong>первой</strong>оплатил</td>
           <td>400</td>
</tr>
<tr>                  
          <td>2017/11/08</td>
          <td>Ваш человек <strong>первой</strong>оплатил</td>
           <td>300</td>
</tr>
<tr>                  
          <td>2017/11/08</td>
          <td>Ваш человек <strong>первой</strong>оплатил</td>
           <td>100</td>
</tr>

request

 $.post("/", {
            action: 'fiterPeriod',
            max: max,
            min: min
        }, function(response) {

            if (typeof response.output !== "undefined") {
                console.log(response.output);
                table.rows().remove().draw();
                table.rows.add(response.output).draw();
                //$(".operations table tbody").html(response.output);
            }else{
                console.log('err');
            }
        }, "json");

This code gives an error
http://joxi.ru/GrqdwPZuQ7OKJA

This error because data is HTML, not array

How I can add rows to table from HTML?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓
    table.rows.add( $(response.output) ).draw();
    

    should do it. That way jQuery basically converts it into nodes for you.

    Allan

  • Kossin17Kossin17 Posts: 3Questions: 2Answers: 0

    Thanks!

    It's work for one item, but if more one row hi is gives error.

    I print to browser log

    console.log(response.output);
    console.log($(response.output));
    

    Result:
    http://joxi.ru/bmo6wPLhxgW44r

    in jQuery nodes has node "text" , but i don't have this node in HTML

    Tell me please where does it come from?

This discussion has been closed.