I am using a JavaScript with jQuery DataTables but I have been having problem in loading the JSON data into the Bootstrap table.
This is a sample of the table
[ { name: 'Bryant Stone', hobbies: 'Football', favorite_team: 'Sea hawks', height: '5 Feet 10 in' },
{ name: 'Jesse Smith', hobbies: 'boxing', favorite_team: 'Spurs', height: '6 feet 6 in' },
{ name: 'Emily Wyclef', hobbies: 'cooking', favorite_team: 'Venus Williams', height: '5 feet 2 in' }
]
In JavaScript I get the data in this format and put it inside JavaScript like this
$(document).ready(function(){
$(\'#respondent\').dataTable({
destroy: true,
data: jsonStr1,
columns:[
{title:"Name", data: "name"},
{title:"Hobbies", data: "hobbies"},
{title:"Favorite team" ,data: "favorite_team"},
{title: "Height" ,data: "height"}
]
});
})
When I load the page it shows my data in the console but a DataTables dialog box shows this message
DataTable warning table id=respondent-
Requested unknown parameter 'name' for
row0, column 0. For information more.....
I don't know what else I can do. It has taken the whole day from me. Any help would be appreciated.
UPDATE Thanks to all who helped by providing some answers all of which i have done. This is my html
<table class="display" id="respondent">
<thead>
<tr>
<th>Name</th>
<th>Hobbies</th>
<th>Favorite Team</th>
<th>Height</th>
</tr>
</thead>
</table>
I have made needed typo correction to the code displayed earlier but I still keep on getting this error message
DataTables warning: table id=respondent-
Requested unknown parameter 'name' for
row 0, column 0, for more information about this
error, please see http://datatables.net/tn/4
I went to the link but could not get anything helpful. After the above message, the table get filled up with empty spaces and after going to some pages I see just one character in the first cell only. Those characters either letter or braces I do not know where they came from because I could not see such sequence in my json data even numbers shows up. It keeps on baffling me I do not know what else to do. Any help would be appreciated.
UPDATE I discovered that the problem was that the data was in a string. Does anyone know how to convert string in javascript to object without using eval(). JSON.parse return string and not object which is what is being looked for.
$(\'#respondent\')