Method Not Allowed http exception using AJAX in Laravel -
what causing exception? meaning of methodnotallowedexception
? using laravel 5.2.
html , input fields:
<div class="form-group"> <label class="control-label">name</label> <input type="text" class="form-control" name="name" id="name" data-validate="required" placeholder="enter name" /> </div> <div class="form-group"> <label class="control-label">detail</label> <textarea class="form-control" name="detail" id="detail" placeholder="enter detail"></textarea> </div> <input type="hidden" id="_token" name="_token" value="{{ csrf_token() }}"> <div class="form-group col-sm-offset-3"> <button type="submit" onclick="postdata();" id="post" class="btn btn-success">submit now</button> </div>
ajax function:
function postdata(){ var name=$('#name').val(); var detail=$('#detail').val(); var token=$('#_token').val(); $.ajax({ type: 'post', url: '{{url("/posts")}}', data: "name="+ name + "&detail="+ detail+"&_token="+ token , success: function(data){ } }); }
route:
route::post('/posts', 'cdesigination@index');
error after clicking button:
methodnotallowedhttpexception in routecollection.php line 219: in routecollection.php line 219 @ routecollection->methodnotallowed(array('get', 'head')) in routecollection.php line 206 @ routecollection->getrouteformethods(object(request), array('get', 'head')) in routecollection.php line 158 @ routecollection->match(object(request)) in router.php line 823 @ router->findroute(object(request)) in router.php line 691
check routes.php file, method using request, should like: route::post('/posts', 'anycontroller@method');
Comments
Post a Comment