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

408
Vistas
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 Respuestas
Responde la pregunta

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