defunkt / jquery-pjax

pushState + ajax = pjax
https://pjax.herokuapp.com
MIT License
16.73k stars 1.97k forks source link

5xx on form POST failing silently #627

Open aleemb opened 8 years ago

aleemb commented 8 years ago

As per documentation,

Response types that force a reload: HTTP response code that is 4xx or 5xx, indicating some server error.

However, for forms via $.pjax.submit this doesn't hold true and causes silent failures without any indication to the user. Would be good if the same could hold true for POST request to forms that result in a 5xx error so PJAX would just show the resulting error page instead of discarding the server response.

markschultz commented 8 years ago

I had the same issue and ended up doing something like this:

$(document).on('pjax:error', function (event, xhr, textStatus, errorThrown, options) {
  event.preventDefault();
  options.success(xhr.responseText, textStatus, xhr);
  $('html').html(xhr.responseText);
});

this will affect all 4xx/5xx not just on post.