1

redux次のようにandを使用して、いくつかのデータを php スクリプトに送信したいと考えてpromiseいます。

export function fetchFileContent() {
    return {
        type: "FETCH_FILECONTENT",
        payload: axios.post("/api/ide/read-file.php", {
            filePath: document.getArgByIndex(0)[0]
        })
    };
}

しかし、php スクリプトはデータを受信できません。$_POSTを使用してすべてのデータを印刷するとvar_dump。中には何もありません。

Google Chrome デバッグ ツールで Request Payloadを確認しましたが、問題ないようです。ここに画像の説明を入力

私のphpスクリプトでは:

if (isset($_POST["filePath"])) 
    echo "yes"; 
else 
    echo "no";
echo "I am the correct file";
var_dump($_POST["filePath"]);

$dir = $_POST['filePath'];
echo $_POST['filePath'];

そして、私はこの応答を得ました:

noI am the correct file<br />
<b>Notice</b>:  Undefined index: filePath in <b>/var/www/html/api/ide/read-file.php</b> on line <b>7</b><br />
NULL
<br />
<b>Notice</b>:  Undefined index: filePath in <b>/var/www/html/api/ide/read-file.php</b> on line <b>9</b><br />
<br />
<b>Notice</b>:  Undefined index: filePath in <b>/var/www/html/api/ide/read-file.php</b> on line <b>10</b><br />

どうすればphpスクリプトのデータを取り戻すことができますか?

4

1 に答える 1

10

Matt Altepeter と彼のコメントのおかげで、次の行を追加して最終的に解決しました。

$_POST = json_decode(file_get_contents('php://input'), true);

したがって、今実行するvar_dump($_POST)と、データを取得できますfilePath

array(1) {
  ["filePath"]=>
  string(10) "/I am here"
}
于 2016-12-29T18:46:10.713 に答える