Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
php result didn't return to html ajax call

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!