ajax is not returning respones to view page in the

2019-09-05 02:41发布

问题:

when I am debugging in firefox console window i can see the output but it's not coming on my viewpage , below i have mentioned my ajax code and my controller, i getting a result but view is not showing

Ajax:

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

   data: {
      id: link   
 }


});
   //alert(data);
}).done(function(data) { // pass the url back to the client after you    incremented it
$('#property').empty('clear').html(data.html);
});
 </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');
        $display = DB::table('property_details')
                  ->where('sale_or_rent', 'LIKE', '%' . $filter . '%')
                  ->get();
                  //var_dump($display); 

                 if(count($display)!=0)
                    {    
                      $returnHTML = view('/pages/fliter')->with('val', $display)->render();
                      return response()->json(array('success' => true, 'html'=>$returnHTML));
                    }
                    else
                    {
                    session::flash('status', 'No Records Found!!!');
                    $returnHTML = view('/pages/fliter')->with('val', $display)->render();
                    return response()->json(array('success' => true, 'html'=>$returnHTML));
                    } 
      } 

回答1:

Should

$('#property').empty('clear').html(row.html);

not be

$('#property').empty('clear').html(data.html);

Also .sucess() is spelt wrong. It should be .success()