Laravel Ajax 500 Internal Server error – 5+ Reasons – Quick Fix

Recently I started working on project using Laravel. I kinda started loving it. The first problem I encountered was with AJAX. I was submitting a form using Ajax. When the form was submitted, the console was logged with 500 Internal Server Error. I dig the problem.I searched the Google for few hours and then I found the solution. Following are the reasons:

Laravel ajax 500 internal server error

500 internal Server Error from Zurb


The  commonest reason for laravel ajax 500 internal server error is missing CSRF token. Specially in Laravel 5. In laravel 5, CSRF token is required on all forms. People usually forget submitting the token with ajax request. Submitting token-less ajax request results in Internal Server Error.

To fix missing CSRF token,  just add a hidden field in the form and BOOM!! .Here is the code for you to add to your form:

1. For Blade Template Users:

<input type="hidden" name="_token" value="{{ Session::token() }}">

2. For non Blade Users:

 <input type="hidden" name="_token" value="<?php Session::token() ?>">

3. Directly as ajax data:

var request = $.ajax({
  url: "script.php",
  method: "POST",
  data: {  _token : <?php Session::token() ?>},
  dataType: "html" 

That’s it, it will solve your problem most of the time. Other reasons that can give you Laravel 500 Internal Server Error problem might be:

Wrong Route:

You may be submitting ajax data to wrong route type and even wrong url (404). So first double check the path you are submitting to. Second, check whether the route accepts “Post” or “Get” data type. Because submitting post data via Get method or vice versa will results in Laravel ajax giving 500 Internal Server Error.

Data Type Returned:

If you are returning Boolean and your ajax code is set for Json or any other data type then chances are that you will stumble up on the internal server error. Try to set data type for all ajax response to json. If you are using jQuery then set dataType to xml, json, script, or html like this:

var request = $.ajax({
  url: "/action",
  method: "POST",
  data: { id : userId },
  dataType: "json"

Cross Domain Configuration:

If you are using ajax for cross domain requests then be sure that you are sending proper headers. In case of jQuery, just set the crossDomain variable to true.Alternatively set dataType to “jsonp”


To be honest, .htaccess contributes to 80% of the web’s 500 internal server errors. Regardless of laravel and ajax. Check your .htaccess file for any error specially after you have edited it.

Syntax Error

If your php file has some error and your hosting provider has configured there servers to give 500 internal server error on all php errors. Then examine your file line by line and find the little bug troubling you.

Directory Permission

In case if the storage directory is not writable by Laravel then it will throw a 500 internal server error. Though this error will occur on all requests to the framework regardless of whether it’s through ajax or not. To fix that, run the following two commands through the command line tool on Ubuntu:

sudo chmod 755 -R laravel
chmod -R o+w laravel/storage

The “laravel” in the above command is the name of the directory where Laravel is installed. For other Linux distros, search for the commands to change the permissions of a directory to make it writable.

The most important thing in fixing your error is to find the cause. If your ajax request gives you 500 internal server error then log the response to console. Alternatively, you can submit a regular form and can see the response of the files. Laravel has good error handling library and it show in details the causative agent.

If your Laravel ajax internal server error still persists, then please let me know in the comments. I will be more than happy to help

20 thoughts on “Laravel Ajax 500 Internal Server error – 5+ Reasons – Quick Fix

  1. Milad says:


    When i want post data to laravel get 500-internal-server-error.

    My route is:
    I post data by Postman in chrome.


    • Hello Milad, have you read the data sent by the server on request? Most of the time, Laravel will help you solve the problem by telling you what’s wrong. Please read it and let me know if you don’t understand what’s wrong with it.

  2. Justine says:

    I have a basic ajax function that returns a text. It works in all other pages except one specific page wherein all ajax functions return internal server error 500 (with the exact same code used in other pages). Any idea why?

  3. Osmel Perez Valdes says:

    Hello Abbas,

    I am using laravel 5.2 and getting 500 Internal Server Error in one ajax response but only in my production server, in the dev server all run good. I suppose is related about permission or something else about the server. What do you think?

  4. Ronit Ghosh says:

    hey, Abbas
    Actually, I made a like and dislike button with ajax in Laravel 5.2 which sometimes work and sometimes give 500(internal Server error).
    I don’t why there is this irregularity, like if it doesn’t work at all, I can do something, but if it works sometimes and doesn’t work at other, its disgusting.

    I really need your help, man

    • Hello Ronit,

      Most of the time when that happened to me was because either csrf token would had expired or I was submitting many requests at same time via ajax. I usually leave the tab open while coding in the IDE and when I send a request after a while, I will get a 500 error on ajax request. I think it’s the same problem. You need to take two steps:

      1. Temporary disable csrf check when the request give you 500 server error and submit another request
      2. If that doesn’t solve the problem, then log all the data sent by server on failure to console console,log(response) and check for error messages sent by laravel.

      There is another reason as well and contrary to the above one, it occurs when you submit too much requests at the same time. Like liking a lot of posts within a minute. It is a problem in laravel core and I haven’t figured it out myself yet because of busy schedule. But the workaround is that I delay every request into a queue to wait before another same type request get completed.

      Apply the above causes of the error to your problem. I hope it will help and if not let me know what error message txt you get/

  5. SABBA says:

    public function edit(Request $request) {

    $this->validate($request, [
    ‘name’ => ‘required|max:75’,
    if($request->ajax()) {
    $tag = Tag::find($request->id);
    $tag->name = $request->name;

    if($request->type == ‘hashtag’) {
    Session::flash(‘message’, ‘Se ha actualizado correctamente el hashtag!’);
    Session::flash(‘message’, ‘Se ha actualizado correctamente la categoria!’);
    return response()->json([‘status’ => ‘ok’]);
    return redirect()->back();
    // return response()->json([‘status’ => ‘ok’]);
    return response()->json([‘status’ => $request->name, “id” => $request->id, “name” => $tag->name]);


    Can anyone tell me what’s wrong with that code?

    If I comment the line where I save a tag, it runs well, if not, it throws me a 500 http error

    • What’s the error message when Laravel give you 500 error? Have you checked that you are passing the correct request id to tag::find()? Kindly create a gist with proper comments and the error data that you get so that we can help you easily.


  6. Hi how are you, you have good topics to help … I ask you I get error 500, for this line, I’m working with vue for the frontend with vuejs
    Failed to load resource: the server responded with a status of 500 (Internal Server Error)


    setTimeout(() => {
    // ‘./programas/updateStatus’, {,status:newStatus})

    headers: {
    ‘x-csrf-token’: document.head.querySelector(‘meta[name=csrf-token]’).content

    .catch(error => {

    this.processing = false;

    }, 2500);

  7. ahmad bilal says:

    AoA Sir , i am search data in laravel using following code but 500 internal server error.. i am unable to solve this issue after five days hard work .. i read your blod about this prob but could not find the solution.please help me.



    function fetch_customer_data(query = ”)
    url:”{{ route(‘live_search.action’) }}”,


  8. I got same error

    controller file:
    * I want update the student status throw this.
    public function changeActiveStatus(Request $request)

    $applicant = Student::find($request->applicant_id);
    $input = $request->all();
    $applicant->status = $request->input(‘status’);;

    return response()->json([‘success’=>’Status changed successfully.’]);

    * blade file\

    applicant_id)}}” target=”_blank” > Download

    function changeUserStatus(_this, applicant_id) {
    var status = $(_this).prop(‘pending’) == true ? ‘success’ : ‘pending’;
    let _token = $(‘meta[name=”csrf-token”]’).attr(‘content’);

    url: “{{route(‘change.status’)}}”,
    type: ‘post’,
    data: {
    _token: _token,
    id: applicant_id,
    status: status
    success: function (result) {

    ##plz help

Leave a Reply