如何在Ajax成功后加载视图刀片

时间:2018-04-13 12:05:08

标签: ajax laravel laravel-blade laravelcollective

我希望在ajax成功后显示刀片表单,但结果无法正确显示...

CategoryController.php

public function edit($id)
{
    $categories = Category::find( $id );

    return view( 'modules.category._form', compact( 'categories' ));
}

_form.blade.php

{!! Form::model($categories, ['url' => route('categories.update', $categories->id), 'method' => 'put']) !!}
<div class="form-group{{ $errors->has('title') ? ' has-error' : '' }}">
{!! Form::label('title','Title') !!}
{!! Form::text('title', null, ['class'=>'form-control','placeholder'=>'Enter title here']) !!}
@if ($errors->has('title'))
<span class="help-block">{{ $errors->first('title') }}</span>
@endif
</div>
<div class="form-group form-actions">
<button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-angle-right"></i> Update</button>
<button type="reset" class="btn btn-sm btn-warning"><i class="fa fa-repeat"></i> Reset</button>
</div>
{!! Form::close() !!}

视图

<div id="form-edit"></div>

<script>
$(function(){    
$('.edit').click(function(){
            var id = $(this).data('id');
             var form_action = $('#edit'+id).data('href');
             $.ajax({
                type: 'GET',
                url: form_action,
                data: { '_method':'PUT','_token':$('meta[name=csrf-token]').attr('content'),'id':id },
                success: function(result){
                    $('#form-edit').html(result);
                    }
             });
          });
});
</script>

结果:

result

表单HTML Laravelcollective不呈现

如何修复itu? ...

0 个答案:

没有答案