Tags down


Internal server error 500 Laravel 5.4 AJAX

By : Peter
Date : October 17 2020, 08:10 AM
hope this fix your issue I'mm using laravel 5.4 and I want to create AJAX that can post data to server but I got this error message , in your routes/web.php
code :
use Illuminate\Support\Facades\Validator;

public function getProfessions(Request $request)

 try {
        $validator = Validator::make($request->all(), [
                'postId' => 'required',
                'body' => 'required'

        if ($validator->fails()) {
            $response=array('status'=>'error','errors'=>implode(',', $validator->errors()->all()));
            return response()->json($response, 200);
           $profession = Profession::where(['categories_id'=>$request->input('postId')])->first();
             return response()->json(['profession'=>$profession], 200);
               $response=array('status'=>'error','errors'=>'profession not found');
               return response()->json($response, 200);

   }catch(\Exception $e){
        $response=array('status'=>'error','errors'=>'Internal Server Error');
        return response()->json($response, 500);
<meta name="csrf-token" content="{{ csrf_token() }}" />

    <input type="hidded" id="postID" name="postID" value="{{$profession->postID}}" />
    <input type="text" id="body" name="body" value="{{$profession->body}}" />
   <button type="button" id="testAjax">Submit using AJAX</button>
     var postID=$('#postID').val();
     var body=$('#body').val();
          url:"{{ route('edit')}}",
          headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},


Share : facebook icon twitter icon

500 Internal Server Error Ajax Laravel

By : AndyWood
Date : March 29 2020, 07:55 AM
Hope this helps I'm trying to make a POST to , Add this in below inside the form.
code :
// This will generate token field which will be token
{{ csrf_field() }}  

// Expected Output
<input type="hidden" name="_token" value="ssdfdsfsdfsdfs32r23442">
<form action="/foo/bar" method="POST">
    <input type="hidden" name="_method" value="POST">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">

Laravel ajax internal servor 500 (internal server-error)

By : Yassine Nada
Date : March 29 2020, 07:55 AM
I wish this helpful for you You're accessing the ajax() method statically (using ::), when you should be using -> instead:
code :
if ($request->ajax()) {

500 (Internal Server Error) ajax and laravel

By : Henrique Santos
Date : March 29 2020, 07:55 AM
Any of those help There are several problems with your code. Firstly; your variable commentId does not exist at the time of your ajax request, thus is it is not present when the controller is called on the php-side of things. Since you are using jQuery, this can be easily fixed.
The main difference between your js and the js below, is that I have replaced your
code :
commentId = event.target.parentNode.parentNode.dataset['commentid'];
commentId = $("#comment-post", event.target.parentNode.parentNode).data('commentid');
$(document).ready(function() {

  var commentId = 0;
  var divcomment = null;

  $('.edit-comment').click(function(event) {
    var divcomment = this.parentNode.parentNode;
    commentId = $("#comment-post", event.target.parentNode.parentNode).data('commentid');
    var commentBody = $(divcomment).find('#display-comment').text();

  $('#modal-save').click(function() {
        method: 'PUT',
        url: urlEdit,
        data: {
          comment: $('#comment').val(),
          commentId: commentId,
          _token: token
      .done(function(msg) {
    console.log("comment id: " + commentId + " comment: " + $('#comment-body').val());

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="modal fade" id="edit-comment" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" style="color:#000;">Editar Comentario</h4>
      <div class="modal-body">
          <div class="form-group">
            <label for="comment">Editar comentario</label>
            <textarea class="form-control" name="comment" id="comment"></textarea>
      <div class="modal-footer">
        <button type="button" class="btn-comment-dismiss btn-comment-modal" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Cerrar</button>
        <button type="button" class="btn-comment-edit btn-comment-modal" id="modal-save"><span class="glyphicon glyphicon-ok"></span> Editar</button>
<article class="row">
  <div class="col-md-3 col-sm-3 hidden-xs">
    <figure class="thumbnail">
      <img class="img-responsive" src="http://placehold.it/200x200" />
      <figcaption class="text-center">User1</figcaption>
  <div class="col-md-8 col-sm-8">
    <div class="panel panel-default arrow left">
      <div class="panel-body">
        <header class="text-left">
          <div class="comment-user"><i class="fa fa-user"></i>User1</div>
          <time class="comment-date" datetime="1 hour ago"><i class="fa fa-clock-o"></i>1 hour ago</time>
        <div id="comment-post" data-commentid="1">
          <p id="display-comment">blah blah</p>

      <div class="panel-footer list-inline comment-footer">
        <a href="#" data-toggle="modal" data-target="edit-comment" class="edit-comment">Editar</a> <a href="#" data-toggle="modal" data-target="delete-comment" class="delete-comment">Eliminar</a>
  method: 'POST',
  url: urlEdit,
  data: {
    comment: $('#comment').val(),
    commentId: commentId,
    _token: token,
    _method: 'PUT'
.done(function(msg) {
comment: $('#comment-body').val(),
comment: $('#comment').val(),

Laravel 500 Internal Server Error Ajax

By : Swapna Yeruvala
Date : March 29 2020, 07:55 AM
this one helps. Here is your fix, you need to call messages like this messages() that will return relationship instance.
code :
public function testFunction(Request $request) {
if ($request->isMethod('post')) {
    $messages = User::find(1)->messages();
    return $messages;
} else {
    return 'get method';

Internal server error 500 when using Ajax and Laravel

By : Cameron Hunt
Date : March 29 2020, 07:55 AM
Hope this helps the bug can occur because it is missing csrf-token
first, add the meta :
code :
    headers: {
        'X-CSRF-TOKEN': $('meta[name=csrf-token]').attr('content')
Related Posts Related Posts :
  • Mongo $addToSet an Array
  • Integrating isotope.js with Wordpress loop
  • Create Admin settings for SugarCRM custom module
  • Storing special characters in DB in such a way to display properly on site and still find image with the same name
  • Obtain value tag from xml
  • PHP Mail with attachment - but file is empty
  • PHP Multiple require, same function
  • Traverse XML file to find products recursively
  • PHP is not displaying 'success' message after writing data to JSON, but data gets added
  • Locate specific text in Google Sheets using the API
  • Laravel, convert to uuid text from uuid binary upon creating model
  • Creating formula
  • Grouped Array data
  • Wordpress get_option() with index key from string
  • PHP Laravel: A better way than these if statements
  • Trying to build my query by fetching column names from the selected table
  • Two values in the same column
  • Exceeding 10 nested forwards?
  • Ternary in associative arrays in PHP
  • simplexml_load_file won't fetch data with an Array
  • php mysql looking how to check if there are no result
  • Laravel filters won't work when trying to add them
  • Checking for duplicate mysql data with bootstrap validator
  • yii2 Error of dynamic client validation URL - Cannot read property 'test' of undefined
  • PHP Script to handle end of year calculation automatically?
  • Saved html is not the same as it's output in the browser
  • Wordpress shows only one post
  • SQL record retrieval
  • PHP return true if all method calls inside a foreach method return true
  • Unexpected error after transfering website to new server - mix of php and html in IF
  • Remove the last part of the comma in foreach in PHP?
  • the_author_meta() wont show inline text in { }
  • How do I create an error handler in php that redirects the user if a specific error occurs?
  • PHPInfo / Valet - Two different PHP versions
  • Connect an active directory or LDAP with PHP
  • How to assign a variable from another file to a class constant?
  • How to remove array index from php array?
  • How to handle multiple paginations with one link
  • Inverting order of exhibition of the elements in PHP
  • Slim 3 withRedirect problem and parameters
  • using Laravel 5.7 : how can i get json value name from an array ?
  • I See a Lot of `<open></close>` Tag Sets That Contain NO Data, Doesn't This Negate the Tag?
  • Calling a class and function using variable
  • php unset foreach loop is not unsetting the value of array
  • Error! The command "tesseract" was not found. (PHP thiagoalessio)
  • Get the catalog visibility for a product in a SQL query on Woocommerce
  • show data from json
  • Laravel - Views - router() doesn't work or I just dumb
  • Return foreach values inside string
  • Add text to a file with PHP SSH2
  • Setting up named routes within a subdomain group in Laravel 5.7
  • Yii2: How to add two fields and NULLS LAST in orderby() of Find() using mysql
  • Removing string characters form mysqli database and utilize two variables derived from database
  • How to update one table from two different pages in laravel
  • Select non-parentheses and non-quotes comma
  • How to filter php array by min/max value
  • how to send an array of URI's from php to python and print it there
  • Php 7.1 Return Type-hint failing in Laravel 5.7
  • Validation in Laravel 5.6
  • filter latest comment using sql
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org