jquery - PHP data not sent by ajax -
i trying pass value ajax get-data.php
. have lot research on stackoverflow. however, still cannot work , not sure why case. whenever var_dump
$_post
, array(0)
.
index.php
<select id="cis_major"> <option disabled selected value> -- select option -- </option> <option value="cs150">cs150</option><option value="cs180">cs180</option> <option value="cs240">cs240</option><option value="cs280">cs280</option> < option value="cs350">cs350</option><option value="cs360">cs360</option> <option value="cs401">cs401</option><option value="cs402">cs402</option> <option value="cs421">cs421</option><option value="cs440">cs440</option> <option value="cs460">cs460</option><option value="cs476">cs476</option> <option value="cs480">cs480</option> </select> <div id="selection"></div> <div id="show"> <!-- items displayed here --> </div> <script type="text/javascript"> $(document).ready(function () { $("#cis_major").on("change", function () { var selected = $(this).val(); $("#selection").html("your selected:" + selected); $.ajax({ type: "post", url: "get-data.php", data: {selected:selected}, success: function (result) { $("#show").html(result); } }); }); }); </script>
get-data.php
<?php var_dump($_post["selected"]); if(isset($_post["selected"])){ /* query here , output want */ echo "i love you"; /* print output want, returned original page */ }
Comments
Post a Comment