سؤال

I want to know how to debug ajax in Laravel 4, because when error, I only get and error 500.

I'm making ajax request with jQuery.

هل كانت مفيدة؟

المحلول 2

Use Laravel Log to debug it in Laravel:

Log::info('Whatever you need to send to your log');

And check your log for your messages and all error messages:

php artisan tail

نصائح أخرى

Another easier answer is:

In Chrome,

  1. go to Network menu
  2. Click the path/error
  3. Go to Preview tab

The full error message is visible there.

Laravel 4.2 and AJAX POST - 500 Internal Server Error

Another way, and, to have more specificity of the error (like 500 Internal Server Error), surround your code into a try/catch block and send the error/exception message as a JSON object for instance.

$.post('http://localhost/post_request,
    {
        '_token': $('meta[name=csrf-token]').attr('content'),
        'input_xxx': 'value'
    })
      .fail(function(data) {
        data.error / data.debug
      })
      .success(function(data) {

    });

--------------***---------------

    try{

        //post request action(s) handling here


    }catch(Exception $e){
            return response()->json([
                'error' => 'Whoops, looks like something went wrong.',
                'debug'=> $e->getMessage()
            ]);
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top