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.
Written by Wojtek Kruszewski
Related protips
1 Response
Just had this same problem. Thank you for your solution!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Validation
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#