NoobNewb
NoobNewb

Reputation: 653

var_dump does not show anything after post

I'm trying to send data from my React app using the Fetch API to a server. For now, I just would like to see what values are actually being sent to the server. When I try to do a var_dump($_POST) nothing happens even when the response status is 200.

React App

sendToPHP = cssObject => {
    let json_str = JSON.stringify(cssObject);
    json_str = encodeURIComponent(json_str);

    fetch("/includes/modules/CertBuilder/api.php", {
        method: "POST",
        body: json_str
    }).then(res => {
        console.log(res);
    });
}

api.php

<?php
require_once('../common.php');
var_dump($_POST) ;

I'm also using Qcodo which I realize is not a common framework these days. Plain PHP is also fine. Any help is appreciated. Thanks!

Upvotes: 1

Views: 372

Answers (1)

Mischa
Mischa

Reputation: 1701

Add a catch-block to debug your code:

sendToPHP = cssObject => {
    let json_str = JSON.stringify(cssObject);
    json_str = encodeURIComponent(json_str);

    fetch("/includes/modules/CertBuilder/api.php", {
        method: "POST",
        body: json_str
    })
    .then(res => {
        console.log(res);
    })
    .catch(error => console.error(error));;
}

Upvotes: 0

Related Questions