2

I'm having a little problem, I've never really used Ajax/Jquery with Laravel before, and I'm having a problem with JQuery $.get() function. I followed a tutorial to make a select input show data from my database on every change. I believe the tutorial was based on laravel 4, and Im using laravel 5.1 I'm stuck at this part:

$.get('/ajax-mascsel?cod_masc=' + cod_masc+, function(data){
console.log(data);
}

This returns the following error on the console:

GET http://localhost/ajax-mascsel?cod_masc=37 500 (Internal Server Error) jquery.min.js:4

Browsing the error, I found out it is a server sided error, and It be caused by a lot of reasons, but the most comon is the csrf_token, my problem here is, I dont know how to solve it function, I know in AJAX you add it in the "header:", but I dont know where in the $.get();

How could I solve this? Also, this is my route processing the ajax request:

Route::get('/ajax-mascsel', function(){
    $cod_masc= Input::get('cod_masc');
    $mascota = Mascota::where('cod_masc', $cod_masc)->get();
    return Response::json($mascota);
});
RodrigoCS
  • 79
  • 8
  • 1
    500 internal server error is usually a fatal error, which shouldn't happen if you haven't messed up something. You should start with checking the web server error logs to see what's going on. – JimL Jan 03 '16 at 10:19
  • 1
    GET requests for Laravel don't require the CSRF token. – Thomas Kim Jan 03 '16 at 10:27
  • Well, I'm stupid :P, yeah it was a really obvious problem with my Model, :/ well I just solved it. I couldn't use my model directly on the route for some reason, so I just changed it for a controller :P, thanks I actually never checked my error log ever before. – RodrigoCS Jan 03 '16 at 10:35

0 Answers0