user5313398
user5313398

Reputation: 753

Laravel post giving 500 (Internal Server Error) but not get method

I have the following which I used to call my ajax upon form submission

$.ajax({
      method: "POST",
      url: "grades/ajaxGradePrice",
      data: { gradeID: $('#GradeID').val()}
  })
  .done(function( msg ) {
      alert( "Data Saved: " + msg );
  });

At my controller is this

public function ajaxGradePrice(){
      //$gradePrice=199;
      //return $gradePrice;
}

My route is this Route::post('grades/ajaxGradePrice', 'GradesController@ajaxGradePrice');

Eventually I get this 500 (Internal Server Error) but surprising when I change all the post to get its working perfectly fine that both the method:"GET" and Route::get('grades/ajaxGradePrice', 'GradesController@ajaxGradePrice');

Upvotes: 0

Views: 1417

Answers (2)

Vikash
Vikash

Reputation: 3541

It seems you are forgetting the csrf token

In your data object which you are passing by ajax, just add "_token": "{{ csrf_token() }}",

Your data object should look like

 data: { gradeID: $('#GradeID').val(), "_token": "{{ csrf_token() }}"}

Upvotes: 1

Saa
Saa

Reputation: 1615

As in comments up here; you're missing the CSRF token in your request.

Add the token to your Ajax POST:

{ gradeID: $('#GradeID').val(),
"_token": "{{ csrf_token() }}" }

Upvotes: 1

Related Questions