我正在尝试使用JQuery简单地发布一些内容。单击该元素时,我希望页面重定向到php文件并回显出POST值。
Html文件
<html>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div onclick="posttest();" >hi there</div>
<script>
function posttest(){
var txt="hi";
$.post("testpost.php", {testVar: txt},function(){
window.location.href = "testpostphp.php";
});
}
</script>
</html>
PHP文件
<?php
var_dump($POST["testVar"]);
?>
答案 0 :(得分:0)
$_POST
个变量,而不是$POST
。试试这个:
$.post("testpost.php", {testVar: txt}, function(response){
console.log(response);
});