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

406
Views
Fetch post method from js to php script(api)

I am new to this part of communication between client site and server. My client is js who fetch object to php script called server.php.

registration.js

let json = {
    name: name,
    date: date,
    phone: phone,
};

     const options = {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify(json),
        };
        fetch(
            `http://localhost/php/server.php/registration`,
            options
        );

How do I know if request is a registration request or something else?

If i create in server.php script

 if (isset($_POST'['registration']) { ... }

php says that is not set $_POST'['registration'];

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

$_POST contains data that is:

  • In the request body
  • Encoded as application/x-www-form-urlencoded or multipart/form-data

Your request body is encoded as application/json so $_POST will be blank, and registration appears in the URL, not the request body anyway.

Look to $_SERVER[PATH_INFO] instead.

Contains any client-provided pathname information trailing the actual script filename but preceding the query string, if available. For instance, if the current script was accessed via the URL http://www.example.com/php/path_info.php/some/stuff?foo=bar, then $_SERVER['PATH_INFO'] would contain /some/stuff.

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