Adding multiple rows with ajax problem
Adding multiple rows with ajax problem
itajackass
Posts: 162Questions: 48Answers: 3
I've a strange problem adding more than one row with ajax.
This is my button to add row retrieved from ajax (see dataType: text):
$("body").on("click","#btn-add", function(e) {
e.preventDefault();
var table= $('#table').DataTable();
$.ajax({
type: "POST",
async: false,
dataType:"text",
url: "ajax/get-rows.php",
data: { },
success: function(data) {
table.rows.add($(data)).draw( false );
}
});
});
This is my get-rows.php
<?php
//START
?>
<tr>
<td>COL 1</td>
<td>COL 2</td>
<td>COL 3</td>
</tr>
<tr>
<td>COL 1</td>
<td>COL 2</td>
<td>COL 3</td>
</tr>
<?php //END ?>
I always get this error:
table id=table- Requested unknown parameter '0' for row 1, column 0
But if I modify get-rows.php to only ONE row it works!
<?php
//START
?>
<tr>
<td>COL 1</td>
<td>COL 2</td>
<td>COL 3</td>
</tr>
<?php //END ?>
What's the problem?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
<?php
<?php > ?>$data[] = array("COL 1"," COL 2","Col 3");
echo json_encode($data);
var dataSet = JSON.parse(data);
table.rows.add($(dataSet)).draw();
may it will help.