javascript - how to pass a jquery variable to php and then display it -
problem in passing jquery variable php .
when pass variable id b.php
getting error
"notice: undefined index: id1 in c:\xampp \htdocs\phpproject1\otherusableitems\b.php on line 2
how solve problem ???? 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 pass on b.php
try 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 ; ?>
Comments
Post a Comment