Problem in passing Jquery variable to php .
When i pass variable id to B.php i am getting this error
"Notice: Undefined index: id1 in C:\xampp \htdocs\PhpProject1\OtherUsableItems\B.php on line 2
How to solve this problem ???? This A.php
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
var id = 23;
$("#submit").click(function(){
$.post("B.php",
{
id1: id,
} );
});
});
</script>
</head>
<body>
<form action="B.php" method="post" >
<input type="submit" id="submit" name="submit"/>
</form>
</body>
</html>
This B.php
<?php
$a =$_POST['id1'];
echo $a ;
?>
I want id variable to pass on to B.php
Try this one:
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
var id = 23;
$("#submit").click(function(){
$.ajax(
{
url: "B.php",
type: "POST",
data: { id1: id},
success: function (result) {
alert('success');
}
});
});
});
</script>
</head>
<body>
<form >
<input type="button" id="submit" name="submit"/>
</form>
</body>
</html>
Then B.php
<?php
$a =isset($_POST['id1'])?$_POST['id1']:'not yet';
echo $a ;
?>
Try changing the input type to button instead of submit
<input type="button" id="submit" name="submit"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With