Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda