Last Updated: February 25, 2016
· wojtekkruszewsk

Display error pages content with PJAX

I want to be a good citizen of HTTP world and respond with 4xx error codes when submitted form has validation errors. Sadly, PJAX fails to display content of those pages. This is how I twist PJAX's arm and force it to handle 422 ("unprocessable entity") like if it was success:

$(document).on('pjax:error', function(event, xhr, textStatus, errorThrown, options){
  if (xhr.status == 422) {
    options.success(xhr.responseText, status, xhr);
     return false;

Yes, this causes pjax:success to be triggered immediately after pjax:error. Oh well.

1 Response
Add your response

Just had this same problem. Thank you for your solution!

over 1 year ago ·