Comments (5)
Basically, browsers didn't (and might still) not support anything other than GET/POST (not including HEAD and OPTIONS). To work around this, Ruby on Rails started adding a _method
parameter to all forms that weren't a GET or POST. This was adopted by other libraries and frameworks, and somewhat became the de-facto standard.
Unpoly works in the same way - the actual request is a POST, but with _method=PUT
as a parameter.
If you're using Rack or something based off it, there is a Rack::MethodOverride
middleware you can use to enable the _method
param.
from unpoly.
Ah, I didn't realize this was a layover from Rails.
However, browsers limiting themselves to GET/POST is only applicable to HTML forms. This is an AJAX request, so it is presumably using XMLHttpRequest under the hood, which does support the PUT method.
More to the point, jQuery's $.ajax()
also supports the PUT method, and since Unpoly is built on top of jQuery, it seems sensible (consistent?) to include the method in its vanilla form, rather than being wrapped in a POST.
from unpoly.
Yes , it was form specific. The original premise was that without Javascript, people still expected forms to submit correctly (ala, the original button_to
helper in Rails).
Since Unpoly wouldn't be used without Javascript enabled, I agree that Unpoly should use the native method where possible.
But looking at the source code, it looks like this is already the case, except Unpoly makes the decision to wrap non-GET/POST methods into a POST, as you're seeing. You just need to tell Unpoly not to wrap them in a POST.
Spitballing here, but you could try this:
up.proxy.config.wrapMethods = []
from unpoly.
Ah, I looked into the source enough to realize that methods were being wrapped, but not closely enough to see that solution.
It worked perfectly, thank you @adam12!
from unpoly.
Also note that while many browsers now support verbs like PUT
, PATCH
, they handle redirect responses in an unexpected way.
That's another reason why many frameworks like Rails, Symfony and Express offer a way to wrap the verb in a _method
param.
from unpoly.
Related Issues (20)
- up-href in table row (tr) not working HOT 1
- event.location from `up:location:changed` is not string when using browser back/forward HOT 2
- "Failed to execute 'querySelectorAll'" when selector contains special characters HOT 2
- CSP blocking `up.reload` even with `unsafe-eval` HOT 4
- Submit via out-of-form element does not contribute the element name/value pair HOT 2
- DOMException: Failed to execute 'matches' on 'Element': ':none' is not a valid selector. HOT 3
- While in an overlay, Unpoly 3 injects a form fragment outside [up-target] after onBlur validation HOT 6
- Cannot submit form containing a field called "contains" in Unpoly 3 HOT 3
- Allow custom navigation feedback HOT 7
- Redirect to new URL
- Wrong cursor position on up-autosubmit form with field type="number" HOT 1
- Using up.on with the passive option set to true raises an unexpected error HOT 2
- Demo: Cookie “_unpoly_demo_layers_session” does not have a proper “SameSite” attribute value HOT 2
- Demo: not latest version of unpoly used
- tiny doc opt: new changes accessible on github HOT 1
- Doc: dead link in url-patterns
- up-alias not matching URL query string with asterix after shash HOT 2
- https://unpoly.com/ broken HOT 2
- Little documentation typo: `Sxee` instead of `See`
- nested up-hungry removes inner hungry elements HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unpoly.