Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda