所以我只是试图将一些用户名从一个php网页传递给另一个,我似乎无法弄明白。也许有一些我不知道的伎俩...
$('#send-message-button').click(function () {
$.ajax({
type: "POST",
url: "composemessage.php",
data: { passedusername: "<?php echo $_GET['username']; ?>"},
success: function(msg) {
window.location.href = "composemessage.php";
},
});
});
页面正确重定向但var_dump为null。
$_POST['passedusername'] = $passedusername;
var_dump($_POST['passedusername']);
我相信我记得有关重定向到您要发布的同一页面的奇怪内容,但我现在找不到任何内容。 真诚的感谢您的帮助。非常感谢!
答案 0 :(得分:1)
$passedusername
是局部变量,可能未定义。
您的代码发送的值将在$_POST['passedusername']
中,因此您应该将作业转发给$passedusername = $_POST['passedusername']
。
答案 1 :(得分:0)
HTTP是无状态的。您已将某些内容发布到某个版本的页面,然后您将被重定向到该页面的另一个实例。一个全新的会议。使用所选浏览器的“检查器”中的“网络”选项卡,查看要发布的页面实际返回的内容。
编辑:正如埃隆所说,你也可以反过来做你的任务。尝试执行print_r($_POST)
以查看返回的内容。