我有下面的代码来创建datatable。
它不是从我的php文件返回json结果,而是返回php文件本身。
我检查了localhost页面上的php文件,看起来php文件运行良好:
{“recordsTotal”:0,"recordsFiltered":115,"data":[{"chr":"chr1","pos":631704},{"chr":"chr1","pos":631714},{"chr":"chr1","pos":631848},{"chr":"chr1","pos":632344},{"chr":"chr1","pos":632461},{"chr":"chr1","pos":633015},{"chr":"chr1","pos":633143},{"chr":"chr1","pos":633300},{"chr":"chr1","pos":633364},{"chr":"chr1","pos":633839},{"chr":"chr1","pos":633852},{"chr":"chr1",“pos”:633860}.
有人能帮我吗?
我尝试了这个答案
PHP code is not being executed, but the code shows in the browser source code
LoadModule php_module "C:/xampp/php/php8apache2_4.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
但还是没用。
`<script>
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {url : "example.php",
type: "GET",
},
"columns": [
{ "data": 'chr'},
{ "data": 'pos'}
]
} );
} );
</script>`
谢谢。
发布于 2022-04-28 19:35:51
尝试添加dataType:"json"..。我也有6个月的Javascript,如果它不起作用,让我知道,我会尝试其他的东西。我在php上工作了20年。
<script>
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {url : "example.php",
type: "GET",
dataType:"json",
},
"columns": [
{ "data": 'chr'},
{ "data": 'pos'}
]
} );
} );
</script>
在你的PHP脚本中..。我不熟悉SSP课程,但你不能这样做吗?这就是我在游戏中如何从php返回json到javascript的方式。
print json_encode(array("food"=>$_SESSION['food'],"wood"=>$_SESSION['wood'],"gold"=>$_SESSION['gold'],"stone"=>$_SESSION['stone']));
然后在javascript内部函数(数据)中使用data.food (在ajax调用之后)
https://stackoverflow.com/questions/72052441
复制