mardi 25 avril 2017

Laravel 5.1 MethodNotAllowedHttpException Error

I'm using resource controller , when i submit form through ajax , it is showing method not allowed exception.

View

 {!! Form::open(array('route' => 'product.store','class' => 'form-horizontal','id' => 'productform','name' => 'productform','files' => true)) !!}
       {!! csrf_field() !!}
       <div class="form-group" style="padding-top: 20px">
            <label for="productName" class="col-sm-3 control-label">Product name</label>
            <div class="col-sm-9">
                 {!! Form::text('productName',null, array('id'=> 'productName','class'=>'form-control','placeholder'=>'Product name'))!!}
            </div>
       </div>                                                            
       <div class="form-group">
            <div class="col-sm-9 col-sm-offset-3">
                 {!! Form::submit('Save', array('class' => 'btn btn-primary btn-block')) !!}
            </div>
                </div>
 {!! Form::close() !!}

AJAX

$("#productform").submit(function () {
    var token = $('[name=_token]').val();
    $.ajax({
        type: 'POST',
        url: 'product/store',
        data: {
            id: '4',
            _token: token,
         },
        success: function (data) {
            alert('success');
            return false;
        }
    })
    return false;
});

routes.php

Route::resource('product', 'ProductController');

What is the problem here...Any help is much appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire