I have the following code to create a datatable.
Instead of return json result from my php file, it returns the php file itself.
I checked the php file on localhost page and it seems the php file is working fine:
{"draw":0,"recordsTotal":115,"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}............
Could someone help me with it?
I tried this answer by adding
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
but still didn't work.
`<script>
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {url : "example.php",
type: "GET",
},
"columns": [
{ "data": 'chr'},
{ "data": 'pos'}
]
} );
} );
</script>`
Thank you.
Try adding dataType: "json"... I'm also 6 months new with Javascript, let me know if it doesn't work and I'll try something else. I've been working with php for 20 years.
<script>
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {url : "example.php",
type: "GET",
dataType:"json",
},
"columns": [
{ "data": 'chr'},
{ "data": 'pos'}
]
} );
} );
</script>
In your PHP script... i'm not familiar with SSP class but couldn't you do something like this? This is how I return json from php to javascript in my game.
print json_encode(array("food"=>$_SESSION['food'],"wood"=>$_SESSION['wood'],"gold"=>$_SESSION['gold'],"stone"=>$_SESSION['stone']));
and then use data.food in javascript inside function(data){ after ajax call