我刚刚使用jquery ajax 例如,此代码将注释框的内容发送到php文件。
$.post("user_submit.php", {
comment: $("#comment").text()
});
问题是我如何在user_submit.php文件中接收数据?
答案 0 :(得分:1)
PHP方面的基本用法是:
echo $_POST["comment"]; // unsafe
请记住基本安全,例如转义:
echo htmlspecialchars($_POST["comment"]); // minimum
答案 1 :(得分:1)
它将在$_POST
数组中:
print_r($_POST);
...这将显示发布到该页面的所有内容。
答案 2 :(得分:1)
使用$.post()
发送的任何数据如下:
$.post("user_submit.php", {
comment: $("#comment").text()
});
收到:
<?php
$comment = $_POST['comment'];
...
?>
答案 3 :(得分:0)
如果您的意思是“我如何收到user_submit.php的输出”,那么解决方案就是使用callback parameter:
$.post("user_submit.php", { comment: $("#comment").text() },
function(data){
alert("Data Loaded: " + data);
});
如果您的意思是“我如何在user_submit.php中收到评论”,那么您应该使用:
htmlspecialchars($_POST["comment"]);
指向htmlspecialchars,$_POST的php手册页的链接。