php - Jquery on change function pass value using ajax to database file .but working only first time -


jquery on change function working first when passing value using ajax jquery function database file using select box.but working first time second time when change value of selected box .its not working why please code given below.

if(isset($package_sort ) && !empty($package_sort ))  {     switch ($package_sort) {      case "1000":        $sql = "select * package package_city='goa' , package_price order package_price asc";             break;     case "160000":         $sql = "select * package package_city='goa' , package_price <=".$_get['package_sort']." order package_price desc";             break;     default:         echo "your favorite color neither red, blue, nor green!"; }  <script>        $(function(){      $(document).on('change', '#package_sort', function(){              var package_sort = $(this).val();              $.ajax({                   url:"package-search.php",                   method:"get",                   data:{package_sort:package_sort},                   success:function(data){                        $("#package_loading").fadein(500).html(data);                   }               });         });       });     </script>   <div class="select-wrapper"><select name="package_sort1" id="package_sort" class="custom-select selectbox">                                                         <option value="" disabled="disabled" selected="selected" hidden="hidden">sort by</option>                                                         <option value="1000" name="package_sort">low height</option>                                                         <option value="160000" name="package_sort">height low</option>                                                      </select></div> 

you have not defined variable $package_sort. need check $_get set or not

if(isset($_get['package_sort']) && !empty($_get['package_sort'] )){     $package_sort = $_get['package_sort'];     switch ($package_sort) {          case "1000":            $sql = "select * package package_city='goa' , package_price order package_price asc";                 break;         case "160000":             $sql = "select * package package_city='goa' , package_price <=".$_get['package_sort']." order package_price desc";                 break;         default:             echo "your favorite color neither red, blue, nor green!";     } } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -