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

105
Views
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
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!