使用prototype获取php脚本中的参数值
我需要向ajax函数发送两个参数。如何获取Php文件中的值?我只写$comment=$\u GET[“comment”];但这并没有发送书面价值 我的原型脚本如下:使用prototype获取php脚本中的参数值,php,prototypejs,Php,Prototypejs,我需要向ajax函数发送两个参数。如何获取Php文件中的值?我只写$comment=$\u GET[“comment”];但这并没有发送书面价值 我的原型脚本如下: comment= $F('comment'); //text from textarea name= $F('name'); // text from text box var ajaxUrl = 'addcomment.php'; new Ajax.Request(ajaxUrl, { method:'po
comment= $F('comment'); //text from textarea
name= $F('name'); // text from text box
var ajaxUrl = 'addcomment.php';
new Ajax.Request(ajaxUrl,
{
method:'post',
parameters: {comment: comment, name: name},
onSuccess: function(data){
alert(data.responseText);
}
});
php:
在PHP中:
$comment = $_POST['comment'];
$name = $_POST['name'];
echo $name.':'.$comment;
您还可以使用以下方法检查发送的所有数据:
print_r($_POST);
您可以通过设置注释和名称(如果不存在)的默认值来进一步了解:
$comment = (isset($_POST['comment']))? $_POST['comment'] : 'Default Comment';
$name = (isset($_POST['name']))? $_POST['name'] : 'Default Name';
在php文件中,请尝试以下操作
<?php
$name = $_POST['name'];
$comment = $_POST['comment'];
echo 'Echoing name : '.$name.'\n'.'Echoing comment : '.$comment.'\n';
?>
您应该将PHP代码更改为
$comment=$_POST["comment"];
$comment=$_POST["comment"];