0

JavaScriptユーザーは、次の/を使用して自分のコンピューターでページを実行しますAjax

xmlhttp.open("POST", "ProcessRequest.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(encodeURIComponent("fname=Mr.&lname=tester"));

サーバー側スクリプト ProcessRequest.php が変数にアクセスできないようです。
たとえば $_POST['fname'] 、次のエラーが発生します。

Notice: 未定義のインデックス: fname

私は何を間違っていますか?私はWAMPを使用してこれを実行しています。

4

1 に答える 1

0

エンコードしすぎです。必要なものは次のようなものです。

xmlhttp.send("fname=" + encodeURIComponent("Mr.") + "&lname=" + encodeURIComponent("tester"));

もちろん、関数を使用してそれをより DRY にすることもできます。

于 2013-03-20T22:20:55.930 に答える