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

166
Vistas
How to retrieve json object at root folder of api?

i try to make api request process on javascript with using root folder only, and there is some problem at input read when the client side request the post through the url. i also create index.php to automaticly execute the request, here is my javascipt code with root folder url

function save_user(){
    var usermail = document.getElementById("emailAddress").value;
    var username = document.getElementById("usernames").value;

    var xhr = new XMLHttpRequest();
    var url = "example.com/source/api/signup/access/";

    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/json");

    xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
      var json = JSON.parse(xhr.responseText);
    }
}

and if i directly request the url to the php file it work fine without any problem, like code below

function save_user(){
    var usermail = document.getElementById("emailAddress").value;
    var username = document.getElementById("usernames").value;

    var xhr = new XMLHttpRequest();
    var url = "example.com/source/api/signup/access/signup.php";

    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/json");

    xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
      var json = JSON.parse(xhr.responseText);
    }
}

<?php
header("Content-Type: application/json");
header("Access-Control-Allow-Headers: example.com");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: POST, OPTIONS");

require_once 'signup.php';

$obj = json_decode(file_get_contents("php://input"));
$cur_email = $obj->email;
$cur_name = $obj->username;

$container = new SighUp();
$respond = $container->SignupUser($cur_email, $cur_name);
echo json_encode($respond);
?>

is there any way to request post using root folder url only or it only can be done with direct url to 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