我发现这段代码看起来适合某些人,
$dataArr['aaData'] = Array();
while($row = $res->fetch_assoc()){
$r = Array();
foreach($row as $key=>$value){
$r[] = "$key $value";
}
$dataArr['aaData'][] = $r;}
header('Content-Type: application/json');
echo json_encode($dataArr);
/* The output will be of the form,
{"aaData": [ [
[
"colname data"
...
],
] */
但是我得到一个错误“表id = datos无效的json响应。
我的数据表列与我的数据库列没有相同的名称,我不知道如何处理它。 这是我的js:
$(document).ready(function() {
function getCpAndVille(data, type, dataToSet) {
return data.cp + " " + data.ville;
}
$('#datos').dataTable({
"order": [[ 3, "desc" ]],
"bProcessing": true,
"sAjaxSource": 'ajx/datatable_process_search.php',
"aoColumnDefs": [
{ "sName": "Réf.", "aTargets": [ 0 ] },
{ "sName": "Poste", "aTargets": [ 1 ] },
{ "sName": "Type de contrat", "aTargets": [ 2 ] },
{ "sName": "Date de publication", "aTargets": [ 3 ]},
{ "sName": "Lieu", "aTargets": [ 4 ], "mData": getCpAndVille },
{ "sName": "Descriptif", "aTargets": [ 5 ] }
],
有人能告诉我我应该使用的正确的PHP代码吗,因为很难找到它,而且我不理解http://www.datatables.net/examples/data_sources/server_side.html中给出的例子
提前致谢。
控制台网络 - > {“aaData”:[[“job_id 9261”,“job_intitule Assistant Achats”,“job_contrat Int \ u00e9rim”,“job_date_insertion 2015-02-20”,“cp 06110”,“job_ville 19”]等等。
答案 0 :(得分:0)