I need to get data from jQuery post request, I think there is some error with routes or controller, here is my javascript request code:
$.post('http://localhost:8000/ajax', { task: "comment_insert", userID: _userID, comment: _comment, name: _name, userName: _userName } ).error( function(data) { alert("Error: "+ data); } ) .success( function( data ) { comment_insert(jQuery.parseJSON( data )); console.log("RESPOND TEXT:" + data); } ); }
There are also my routes for the Laravel framework:
Route::post('ajax', ' AjaxController@index ');
Controller:
class AjaxController extends Controller { public function __construct() { $this->middleware('guest'); } public function index() { return view('ajax.ajax'); } }
my ajax.PHP script is in /resource/views/ajax/ajax.php Also, if I put the script in /public/ajax/ajax.php everything works fine .... I am using Laravel 5 ... Please help
EDIT:
I found that the problem, but I do not know how to solve it.
When I disable csrf protection from: working with kernel.php kernel code, does anyone know how to enable csrf protection code?
source share