简体   繁体   中英

AJAX Internal Server Error 500 Laravel 5.4

I am using ajax to push my data in database in laravel 5.4 because i don't want to refresh the page or redirect somewhere when i push data and i get this error internal server error 500. I am new to ajax btw, maybe the error is so simple yet i don't know. Any help would be much appreciated. Here is the code in my ajax.

var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
$.ajax({
      method : "post",
      url : '../../myroute',
      data : { '_token' : CSRF_TOKEN, 'varForController' : varInJavaScript, 'varForController' : varInJavaScript, 'varForController' : varInJavaScript,
      },
      success: function(json){
        // console.log(json);
      },
      error: function(a,b,c)
      {
        console.log(b);
      }
    });

and here is my route

Route::post('myroute', 'MyController@functionInController');
  var CSRF_TOKEN = "{{ csrf_token() }}";

  $.ajax({
       method : "post",
       url : '../../myroute',
       data : { '_token' : CSRF_TOKEN, 'varForController' : varInJavaScript, 'varForController' : varInJavaScript, 'varForController' : varInJavaScript,
  },
  success: function(json){
    // console.log(json);
  },
  error: function(a,b,c)
  {
    console.log(b);
  }
});

Try this code in your blade file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM