jquery - Pass value from ajax variable to a php variable -
when use ajax value in server side, on successful execution can shown using
.done(function(data) {console.log(data)}
the result of ajax inside "data". question can pass value of "data" in php variable.
my scenario : there dropdown, below html table. when user selects item in dropdown, using ajax selected values passes in "data".
after running mysql query
"select name, age, sex student name = '{$retvalue}';
now instead of "??", want pass value inside "data" in php variable $retvalue
.
how can achieve this?
i have tried level best , after thorough search in net, not able find anything.
code follows : main - file
<?php include ("dbcon.php"); include ("included_functions.php"); ?> <section> <script type="text/javascript" src="<?php bloginfo('template_url');?>/js/jquery.min.js"></script> <script src="<?php bloginfo('template_url');?>/js/jquery-1.9.1.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#fyearddl").change(function(){ /* drop down list */ var fyear = $(this).val(); data = {fyear:fyear}; $.ajax({ type: "get", url: '<?php bloginfo("template_url");?>/showonselectfy.php', data: data, cache: false }) .done(function(data) { console.log(data); $('#inboxfy').empty(); $('#inboxfy').val(fyear); }) }); }); </script> <div style="width:100%; height:30px; padding-bottom:45pt; background-color:#fff"></div> <form id="formcatg" action="" method="post"> <div class="centr-div"> <div class="divbox"> <label id="ddltxt">to view : </label> <?php $fyquery = "select fyear finyear"; $fyresult = mysqli_query($connection, $fyquery); echo "<select id='fyearddl' name='fyearddl'>"; echo "<option value = '-- select financial year --'>-- select financial year --</option>"; while ($resultarr = mysqli_fetch_assoc($fyresult)){ echo "<option value = '$resultarr[fyear]'>$resultarr[fyear]</option>"; } echo "</select>"; ?> <input id="inboxfy" type="text" name="inboxfy" value="" style="width:20%; height:15pt" /> </div> <div id="tablediv" class="scroll"> <table id="showselfy"> <thead> <tr> <th>s.no.</th> <th>quantity</th> <th>price ( £ ) </th> </tr> </thead> <?php //$query="select rt_id, rt_qty, rt_cost,fin_yr rate_mast fin_yr='2014-2015'"; $ddlvalue = $_post['fyearddl']; $query="select rt_id, rt_qty, rt_cost rate_mast fin_yr='{$ddlvalue}'"; $retval = mysqli_query($connection, $query); while( $retvalarr = mysqli_fetch_assoc($retval)){ ?> <tbody> <tr> <td><?php echo $retvalarr['rt_id'] ?></td> <td><?php echo $retvalarr['rt_qty'] ?></td> <td><?php echo $retvalarr['rt_cost'] ?></td> <td style="display:none"><?php echo $retvalarr['fin_yr'] ?></td> </tr> </tbody> <?php } ?> </table> </div> <span id="dataresult"></span> </div> </div> </div> </form> </section> <?php mysqli_close($connection); ?> <?php //get_footer(); ?>
showonselectfy.php
<?php var_dump($_get); ?> <?php include("dbcon.php"); include("included_functions.php"); if(isset($_get['fyear'])){ $getfinyear = $_get['fyear']; echo $getfinyear; } ?> <?php mysqli_close($connection); ?>
Comments
Post a Comment