Storing data in datebase using jQuery Ajax Post mathod via RESTful Resource Controller in Laravel 5.2 -


i new laravel. i'm trying store data in form using jquery ajax (using post method). i'm using restful resources controller handle store request. when using form post method possible use route /student/store.but how can route store method in controller in method. simplified code follows. needed.

("#btnsave").click(function(){     console.log("btnsave");     $.post("/student",     {                 name: $("#studentname").val(),         age: $("#studentage").val(),         marks: $("#marks").val()      },function(data, status){         alert("data: " + data + "\nstatus: " + status);     }); }); 

with resource routes,

route::resource('student', 'studentcontroller'); 

the post request routed store() method default. can see url doing following in console:

php artisan route:list | grep student 

if manually adding form fields ajax request, forgetting csrf token. add following inside form if hidden _token field missing:

{{ csrf_field() }} 

and update ajax request reflect new _token field:

$.post("/student", {             name: $("#studentname").val(),     age: $("#studentage").val(),     marks: $("#marks").val(),     '_token': $('input[name="_token"]').val() } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -