Vallavan J Vallavan J - 6 months ago 14
Ajax Question

Ajax response is not coming on View Page

My ajax is working fine and I am trying to return ajax response on my view page but it's not returning anything but in alert i can see response generated by ajax so please suggest me how i can return ajax response to my page..

Ajax:

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

data: {
id: link
}

}).done(function(data) {
$('#property').html(data.html);
alert(data.html);
});

});


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));
}
}


html:

<div class="container">
<div class="block-content block-content-small-padding">
<div class="block-content-inner">
<h2 class="center">Recent Properties</h2>
<ul class="properties-filter">
<li class="selected"><a href="#" data-filter="*" ><span>All</span></a></li>
<li><a href="{{URL::to('\p_details?id=featured')}}" id="featured" data-filter=".property-featured" class="click"><span>Featured</span></a></li>
<li><a href="{{ URL::to('\p_details?id=rent')}}" id="rent" data-filter=".property-rent" class="click"><span>Rent</span></a></li>
<li><a href="{{ URL::to('\p_details?id=sale')}}" id="sale" data-filter=".property-sale" class="click"><span>Sale</span></a></li>
</ul>


<div class="properties-items isotope" style="position: relative; overflow: hidden; height: 810px;">
<div class="row property">
@foreach($val as $value)
<div class="property-item col-sm-6 col-md-3 isotope-item " style="position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">
<div class="property-box">
<div class="property-box-inner">
<h3 class="property-box-title"><a href="#">{{$value->city}}</a></h3>
<h4 class="property-box-subtitle"><a href="#">{{$value->state}}</a></h4>
<div class="property-box-picture">
<div class="property-box-price">{{$value->property_price}}</div>
<div class="">
<a href="#" class="property-box-picture-target">
<img src="images/test/{{$value->image}}" alt="">
</a>
</div>
</div>
</div>
</div>
</div>
@endforeach
</div>
</div>
</div>
</div>
</div>

Answer

I have write the sql query like this 2 foreach loop working fine. I am not using any ajax call in this function.

Html   
            <div class="block-content-inner">
                    <h2 class="center">Recent Properties</h2>
                    <ul class="properties-filter">
                        <li class="selected"><a href="#" id="All" data-filter="*" class="click"><span>All</span></a></li>
                        <li><a href="#" id="featured" data-filter=".property-featured" class="click"><span>Featured</span></a></li>
                        <li><a href="#" id="rent" data-filter=".property-rent" class="click"><span>Rent</span></a></li>
                        <li><a href="#" id="sale" data-filter=".property-sale" class="click "><span>Sale</span></a></li>
                    </ul>
                    <div class="properties-items isotope"  style="position: relative; overflow: hidden; height: 810px;">
                        <div class="row ">
                            @foreach($rent as $value)
                                <div class="property-item property-rent  col-sm-6 col-md-3 isotope-item" style="position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">
                                    <div class="property-box">
                                        <div class="property-box-inner">
                                            <h3 class="property-box-title"><a href="#">{{$value->city}}</a></h3>
                                            <h4 class="property-box-subtitle"><a href="#">{{$value->state}}</a></h4>
                                            <div class="property-box-picture">
                                                <div class="property-box-price">{{$value->property_price}}</div>
                                                <div class="">
                                                    <a href="#" class="property-box-picture-target">
                                                        <img src="uploads/{{$value->image}}" alt="" style="width: 275px;height: 200px;">
                                                    </a>
                                                </div>
                                             </div>
                                        </div>
                                    </div>
                                </div>
                               @endforeach
                               @foreach($sale as $val)
                                <div class="property-item property-sale  col-sm-6 col-md-3 isotope-item" style="position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">
                                    <div class="property-box">
                                        <div class="property-box-inner">
                                            <h3 class="property-box-title"><a href="#">{{$val->city}}</a></h3>
                                            <h4 class="property-box-subtitle"><a href="#">{{$val->state}}</a></h4>
                                            <div class="property-box-picture">
                                                <div class="property-box-price">{{$val->property_price}}</div>
                                                <div class="">
                                                    <a href="#" class="property-box-picture-target">
                                                        <img src="uploads/{{$val->image}}" alt="" style="width: 275px;height: 200px;">
                                                    </a>
                                                </div>
                                             </div>
                                        </div>
                                    </div>
                                </div>
                               @endforeach




                        </div>
                    </div>
                </div>

sql query:

    public function index()
{


    $rent=DB::table('property_details')
    ->Where('sale_or_rent', '=', 'rent')
    ->take(8)
    ->get();

    $sale=DB::table('property_details')
    ->Where('sale_or_rent', '=', 'sale')
    ->take(8)
    ->get();


    $data=array('rent'=>$rent, 'sale'=>$sale);
    return View::make('index')->with($data);
}