error 1
error 1
please, please,please,please someone HELP1.I am new to datatable, json, ajax and js. I have been stuck on this for 3 days and everytime I sit at my computer desk, I wan t puke.......I am trying to get data from json file into datatables and keep receiving error1. I have been all over this on the web and everything. I cannot get it to work. Please again HELP!
<div class="col-xs-12 col-md-12">
<div class="card">
<div class="card-header .text-center">
<h2 class="text-mito_blue text-left">Add New Testimonials</h2>
</div>
<div class="card-body">
<table id="example" class="table table-responsive table-hover display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
JS
$(document).ready(function(){
$('#example').DataTable({
"pagingType": "simple",
"ajax" : "json/test.json",
"columns" : [
{ "data" : "name" },
{ "data" : "position"},
{ "data" : "office"},
{ "data" : "extn" },
{ "data" : "start_date"},
{ "data" : "salary"}
]
}); });
JSON
json/test.json
{
"data": [
{
"id": "1",
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"id": "2",
"name": "Garrett Winters",
"position": "Accountant",
"salary": "$170,750",
"start_date": "2011/07/25",
"office": "Tokyo",
"extn": "8422"
},
{
"id": "3",
"name": "Ashton Cox",
"position": "Junior Technical Author",
"salary": "$86,000",
"start_date": "2009/01/12",
"office": "San Francisco",
"extn": "1562"
}
]
}
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
Add New Testimonials
JS
$(document).ready(function(){
$('#example').DataTable({
"pagingType": "simple",
"ajax" : "json/test.json",
"columns" : [
{ "data" : "name" },
{ "data" : "position"},
{ "data" : "office"},
{ "data" : "extn" },
{ "data" : "start_date"},
{ "data" : "salary"}
]
}); });
JSON
json/test.json
{
"data": [
{
"id": "1",
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"id": "2",
"name": "Garrett Winters",
"position": "Accountant",
"salary": "$170,750",
"start_date": "2011/07/25",
"office": "Tokyo",
"extn": "8422"
},
{
"id": "3",
"name": "Ashton Cox",
"position": "Junior Technical Author",
"salary": "$86,000",
"start_date": "2009/01/12",
"office": "San Francisco",
"extn": "1562"
}
]
}
I don't immediately see anything wrong there. Can you link to the page showing the issue please? If not that, then the debugger might record something that is useful for us.
Allan
Allan. I cannot as it is housed on the local server. I can, however grant you access to the server. If that is ok. Let me know and I can private message you with log on details.
That would be perfect thanks. If you could PM me by clicking my name above and then the "Send message" button.
Thanks,
Allan
Please close case