-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pjax visits URL after server returned error 500 on form submission #342
Comments
This is most likely caused by that Pjax falls back to normal page load (via This does not meet the standard/default behavior that it should navigate to the response document without sending a new request regardless of whether the response body is empty and whether the structure matches. However, the currently available Web APIs do not allow Pjax to achieve the standard behavior. There's no API to "terminate" all page scripts (documents with mismatched structure are considered incompatible with Pjax documents, so a full/standard/browser navigation is required), and no API to show the browser default 500 page. The best solution for Pjax I can think of is a Possible solutions for you:
|
Thank you for possible solutions. Will you create Pjax config option to modify the current behavior? |
Hi, I think that Pjax should not create second request. It should display html content if available, for example with document.write because there can be html error descripttion with error 500. Pjax could be also configured to handle different mime types if no html is available. |
Pjax can be seperated into two parts, the core and the "trigger". The core handles page navigations, the trigger triggers the navigations. As in Q Why the assign is used for almost every kind of error? As in the previous comment, currently there's no suitable API to achieve the desired native navigation behavior. There is really no good choice for Pjax. In a native navigation, the browser unloads the current page and loads the new page. Pjax is used to avoid the unload of structure-matching pages and to simulate the load of such pages. The available Web APIs can only simulates the load, not the unload. Q Why not ignore the unload and just replace all the elements? These are all more prone to errors. Most scripts are designed to work with normal (not html/head/body-replaced) pages, they may rely on some particular elements, some particular variables, etc. Scripts in Pjax sites are designed to work with structure-matching pages. If you insist on using The best way to handle the errors is to handle on your own. Different sites have different preferences. Some may prefer to show a dialog on errors, some may prefer to show a text next to the form, while some may prefer to redirect to a different page. Different servers may have different error message formats, too. Refer to the last two points of my last comment for some basic usages. Note that As of v2.4.0, // UNOFFICIAL usage.
var pjax = new Pjax({
// ...
});
pjax.load = (req) => pjax
.weakLoad(req)
.catch((e) => {
// ... your own error handling
// `e.detail` has more details like the request, response, document...
}); The default trigger is not fully tested. It's more encouraged to write your own trigger for your specific case to catch and handle the errors yourself. (listen to the related link/form events yourself, call |
Describe the bug
Hi, when a form is submitted and server return code 500 then Pjax tries to visit the form URL with GET again. This can result in 405 Method not allowed. See:
To reproduce
Expected behavior
Response is displayed and no second request is made.
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: