mercredi 9 mars 2016

how to write ajax onclick function do not refresh the page and fliter the data from database using laravel5

My ajax is this:

<script>
    $('.click').click(function(evt)
      {
          evt.prevent Default();
         var link = $(this).attr('id');
         $.ajax({
         type: "GET",
         url: "{{url('p_details')/}}",
         dataType: "json",
        data:{
             id:link
            },
      });

          })
      .sucess(function(data)

               { 
        if (data && data.hasOwnProperty('url')) {
         \\ window.location = data.url;
                 }
              });
          </script> 

controller:

     public function index()
                {
             //$filter=Input::get('id');
           //var_dump($term);
            $view=DB::table('property_details')
         ->Where('sale_or_rent', '=', 'rent')
            ->orWhere('sale_or_rent', '=', 'sale')
           ->get();
         //  var_dump($view);
        return view::make('index', array('val'=>$view));
    }

        public function getPropertyDetails() {

              $filter = Input::get('id');
              $view = DB::table('property_details')
            ->where('sale_or_rent', 'LIKE', '%' . $filter . '%')
            ->get();
        //return Response::json($view);
        return view::make('index', array('val'=>$view));
           } 

How to filter the data from database how to call ajax and controller in onclick function

In these p_details is property details table having a column sale_or_rent In homepage two link button rent and sale how to filter on click the link to get result.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire