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

110
Visualizações
Running php files from javascript on linux

I am running fetch as a way to run php files from javascript. Specifically, the following code is executed

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>test</title>
  </head>
  <body>
    <form name="form" id="form">
      <input type="text" id="text">
      <button type="button" onclick="push()">push</button>
    </form>

    <script>
        async function push(){
          var form = document.form;
          console.log(form.text.value);
          await fetch('test.php?text='+ form.text.value)
          .then(res=> {return res.text();})
          .then(res => {
            console.log(res);
            var result = JSON.parse(res);
            console.log(result.result);
            console.log(result.msg);
          });
        }
    </script>
  </body>
</html>

<?php
    if(isset($_GET['text']) && $_GET['text']!=""){
        $result = "OK";
        $msg = $_GET['text'];
    }else{
        $result = "NG";
        $msg = "message";
    }

    $result = json_encode(
        array(
            "result" => $result,
            "msg" => $msg,
        )
    );

    echo $result;
    return $result;
?>

This works fine on windows, but does not work on linux. The entire php script is returned in console.log(res). Do you know why?

The linux environment uses the following

OS: Debian GNU/Linux 10 \n \l

PHP: PHP 7.3.31-1~deb10u1 (cli) (built: Oct 24 2021 15:18:08) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.31, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.31-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies

Do I need some kind of spell to make it recognize the php file?

about 4 years ago · Juan Pablo Isaza
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