mardi 23 février 2016

Advance Search using Dropdown in Laravel 5

I have a dropdown in dropdown four options are there and I'm trying to filter the data from database according to selected option, I have checked in console data is coming but in my view page data is not refreshing, I have attached image please check that, I'm Struggling please help.

This is my HTML Code view check this image for html view reference

   <select id="property_id" name="property_type" onchange="property_type(this.value)">
        <option>Property Type</option>
        <option value="Single Family Home">Single Family Home</option>
        <option value="Multi_Family_Home">Multi Family Home</option>
        <option value="Condominium">Condominium</option>
        <option value="Townhome">Townhome</option>
   </select>

This my Controller Code to fetch the Data from Database

 public function property_type()
         {
          $term=Input::get('ptyname');
          $data = array();
          $display = DB::table('property_details')
                    ->where('property_type', 'LIKE', '%'.$term.'%')
                    ->Where('sale_or_rent', '=', 'sale')
                    ->get();
          var_dump($display);  
        if(count($display)!=0)
            {    
  return View::make('/pages/property_home', array('row'=>$display));
            }
            else
            {
            session::flash('status', 'No Records Found!!!');
    return View::make('/pages/property_home', array('row'=>$display));
            }
   }

This is My Ajax to load the controller

<script>
   (function($) {
       $('#property_id').on('change', function() {
            var optionSelected = $(this).find("option:selected");
             var prop_type = optionSelected.val();
        $.ajax({
               type: "GET",
               url: "{{URL::to('pages/property_type') }}",
               dataType: "json",
               data: {ptyname: prop_type},
               success:function(row)
            {
                alert(val);
                $("").html();
            }
         }); 
     });
})(jQuery);

This is my Routes

  Route::get('/property_type', array('as' => 'property_type', 'uses' => 'PageController@property_type'));



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire