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

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

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 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