I have a table and I need to read a row and get all the ex. th. I wrote something like this, but it gives me the same array twice ['id','test'].
How should I do this? As I have to process each th in php class to build a table.
<script type="text/javascript">
$(document).ready(function(){
var table = $("table");
var headerCells = table.find("thead th");
var headers = [];
//get header cells
headerCells.each(function(i) {
i = $(this).text();
headers[headers.length] = i;
});
//convert array to json
var jsonArray = JSON.stringify(headers);
//prepare POST data
var dataToPost = { 'jsonArray':jsonArray };
console.log(headers);
$.ajax({ url: '/js/call.php',
data: {data: dataToPost},
type: 'get',
success: function(output) {
//output = eval( '(' + output + ')' );
alert (output);
}
});
}); //end jQ
</script>
The problem is the ajax request
dataToPost is an object but string is expected, solution:
See example