以下是我的js
$(document).ready(function() {
$.ajax({
url: url + 'project/get_project_list',
method:'post',
dataType:'xml',
success:function(data){
$('#datatable').dataTable({
data:data,
columns:[
{
"data" : "projectName"
},
{
data : "projectDescription"
},
]
});
}
});
});
$('#datatable').DataTable();
</script>
<div class="panel-wrapper">
<form id="form1">
<table id="datatable">
<thead>
<tr>
<th>Project Name</th>
<th>Project Description</th>
</tr>
</thead>
</table>
</form>
</div>
我的回复如下
<projectList>
<exceptionId>0</exceptionId>
<id>0</id>
<isException>false</isException>
<offExptionid>0</offExptionid>
<listException>false</listException>
<listExceptionId>0</listExceptionId>
<listSize>0</listSize>
<nextPage>false</nextPage>
<pageNumber>0</pageNumber>
<projectBOs>
<exceptionId>0</exceptionId>
<id>0</id>
<isException>false</isException>
<offExptionid>0</offExptionid>
<projectDescription></projectDescription>
<projectId>5</projectId>
<projectName>Bmw</projectName>
</projectBOs>
<projectBOs>
<exceptionId>0</exceptionId>
<id>0</id>
<isException>false</isException>
<offExptionid>0</offExptionid>
<projectDescription>Toyota</projectDescription>
<projectId>4</projectId>
<projectName>Toyota global</projectName>
</projectBOs>
<projectBOs>
请帮助我如何将projectname和projectdescription绑定到表中 目前它表示表格中没有数据。我不知道使用数据表
答案 0 :(得分:0)
您可以尝试JSON类型数据..
dataType:'JSON',
并传递二维数据
success:function(data){} //data should be two dimentional
答案 1 :(得分:0)
<script>
$(document).ready(function() {
var oTable = $('#tableId').dataTable( {
"processing": true,
"ajax": {
"url": "verify",
"dataSrc": "",
"type": "GET"
},
"columns": [
{ "data": "Emp_id"},
{ "data": "Emp_Name" },
{ "data": "Emp_PAN" },
{ "data": "Emp_Email" },
{ "data": "Emp_Address"}
]
});
});
</script>
这里“verify”是我从DB获取数据然后转换为JSON并使用ajax传递的文件。