I have a simple question about jquery passing variable to php, here is my code, it doesnot work, Can some one helpe me?
javascript:
$(function(){
var txt_value='aa';
$.post("test1.php", {txt_value:txt_value});
});
test1.php
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.post demo</title>
<script src="./report_js/jquery-1.10.2.min.js"></script>
<script src="./a.js"></script>
</head>
<body>
<form action="test1.php" id="txt_value">
<?php
$a=$_POST['txt_value'];
echo "$a";
?>
</form>
</body>
</html>
There is no value printed in test1.php I also tried use callback function, if I use following javascript, it always shows the code of test1.php, not the variable I want to pass javascript:
$(function(){
var txt_value='aa';
$.post("test1.php", {txt_value:txt_value},
function(data){
alert(data);
});
});
Even I change my php code as follows, it still doesnot output correct value in php
<?php
$a=$_POST['txt_value'];
echo "$a";
?>
And I merge jquery js with my own js. Is there anything I need to do with my js? Thanks.