Ajax响应不会出现在View Page上

时间:2016-03-11 05:51:09

标签: javascript ajax laravel laravel-5 onclick

我的ajax工作正常,我试图在我的视图页面上返回ajax响应,但它没有返回任何东西,但在警报中我可以看到ajax生成的响应所以请建议我如何将ajax响应返回到我的页面..

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

});

控制器:

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>

1 个答案:

答案 0 :(得分:0)

我已经编写了这样的2个foreach循环的sql查询正常工作。 我没有在这个函数中使用任何ajax调用。

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查询:

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