2

I'm building a web app using Laravel 4. Nearly all links on my site load content via jQuery AJAX. However when I'm building, and Laravel throws an error, the error page doesn't get displayed in my target area. So I end up disabling AJAX most of the time so I can see the errors thrown by Laravel.

Is there something I can change with my AJAX loader that would display the Laravel errors?

function LoadContent( url, target, method, data )
    {
        $(target).fadeOut(20);

        var loadingTimeout = setTimeout(function() { $(target).html('<div style="text-align:center;font-size:150%;">Loading ...</div>').fadeIn(200); }, 1000);

        var request = $.ajax({ url: url, type: method, data: data });

        var tooLongTimeout = setTimeout(function() { request.abort(); request = false; $(target).html('<div class="large-9 large-centered columns"><h1>Request Failed</h1><p>Please try again or contact us to report the issue.</p></div>').fadeIn(200); }, 60000);

        request.done( function(result) {
                clearTimeout(loadingTimeout);
                clearTimeout(tooLongTimeout);
                $(target).html(result).fadeIn(50);
                AjaxElements();
        });
    }
2
  • Could you try puting your code in a try-catch block and catching the errors server side, and then return a json encoded error message? I haven't run into this issue myself before, but this would be my first approach. Also, after re-reading your question, you might be better off doing unit tests on your server side code instead of trying to debug client side. Commented Nov 27, 2013 at 22:24
  • if you are using Google Chrome, You can see the Laravel error. right click -> inspect element->network section will show you the actual error message. Commented Nov 28, 2013 at 3:18

1 Answer 1

2

You can fetch all the AJAX errors with this nifty function. Then you just display the JSON object you get from Laravel in the console. I use this often.

$(document).ajaxError(function(event, jqxhr, settings, exception) {
  var error = $.parseJSON(jqxhr.responseText);
  console.log(error.error)
});

There is also a lot more info you can get with this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.