フォーラムでは、AJAX GET または POST メソッドを介して送信されたエンコードされた文字列を PHP が自動的に変換するという意見が聞かれます。encodeURIComponent() 関数を使用してエンコードされた ajax post メソッドを使用してデータを送信しました。私のコードセグメントは次のとおりです。
var name = document.getElementById("name").value;
var url = "decode.php";
var param = "name=" + name;
ajaxRequest.open("POST", url, true);
//Send the proper header information along with the request
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", param.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(encodeURIComponent(param));
サーバーがそれを受信すると、次のようにエコーしようとすると(結果はajax応答を介して表示されます)、空の文字列のみが表示されます:
<?php
$content = $_POST['name'];
echo $content;
?>
PHP が正しい入力文字列を返すようにするにはどうすればよいですか? 私は混乱しています!