【问题标题】:L5.1 Loading blade partial via ajaxL5.1 通过 ajax 加载刀片部分
【发布时间】:2016-03-25 14:39:54
【问题描述】:

我的部分循环画廊图片:

<div id="galleryimgs" class="row">
    @foreach($images as $key => $value)
        <div class="col-lg-2 col-md-4 col-xs-6 thumb">
            <img class="img-responsive" src="{{ $value }}" alt="" style="margin-left: auto; margin-right: auto;">
            <div class="galleryremovebutton">
                <a href="/admin/offer/gallery/delete/{{ $offer->id }}/{{ $key }}" class="btn btn-danger" role="button">Izbrisi sliku</a>
            </div>
        </div>
    @endforeach
</div>

我的 dropzone 完成事件:

Dropzone.options.myGalleryDropzone = {

                paramName: "file", // The name that will be used to transfer the file
                maxFilesize: 2, // MB
                parallelUploads: 8,
                complete: function (response) {
                    $.getJSON( "/admin/offers/reload-gallery/{{ $offer->id }}", function( data ) {
                        $("#galleryimgs").html(data);
                    });
                }
            };

我得到的回应如下:

{"images":{"30":"\/media\/30\/conversions\/gallerythumb.jpg","31":"\/media\/31\/conversions\/gallerythumb.jpg"},"offerid":"65"}

现在我需要用这个响应重新加载上面的部分循环......

有什么想法吗?

【问题讨论】:

    标签: jquery ajax laravel-5.1 dropzone.js


    【解决方案1】:

    试试这个方法:

    在你的控制器方法中:

    public function yourMethodName($id)
    {
        // other code..
        return response([
            'status' => 'success',
            'html'   => view('path.to.partial_file', compact('images', 'offer'))->render();
        ]);
    }
    

    现在在您的 ajax 处理程序中:

    $.getJSON( "/admin/offers/reload-gallery/{{ $offer->id }}", function( data ) {
        if(data.status === 'success') {
            $("#galleryimgs").html(data.html);
        } else {
            console.log('Some Error Occurred.');
        }
    });
    

    这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 2013-01-10
      • 2018-03-09
      • 2014-09-15
      • 2018-05-19
      • 2021-03-09
      相关资源
      最近更新 更多