简体   繁体   English

JQuery 非常简单的 POST 不起作用

[英]JQuery Very simple POST not work

I'm trying to simply POST something using JQuery.我正在尝试使用 JQuery 简单地发布一些内容。 when the element is clicked, I want the page redirect to the php file and echo out the POST value.单击元素时,我希望页面重定向到 php 文件并回显 POST 值。

Html file 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 file PHP文件

<?php
var_dump($POST["testVar"]);
?>
  1. There is $_POST variables in PHP, not $POST . PHP 中有$_POST变量,而不是$POST
  2. Try this:尝试这个:

     $.post("testpost.php", {testVar: txt}, function(response){ console.log(response); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM