3 ms·
That's really cool! I didn't know about this. Thanks for sharing. How do you handle reflecting the new state in the UI though? Do you just use JavaScript anywa
by yakshaving_jgt 5y ago
That's really cool! I didn't know about this. Thanks for sharing.
How do you handle reflecting the new state in the UI though? Do you just use JavaScript anyway?
I have a form which looks like a toggle, and interacting with the toggle initiates a POST request. If the server responds with a 204, the UI doesn't actually update to reflect the new toggled state. I'm not sure how to work around this.
- fathyb 5y agoCould you do something like "<form action="#sent">" and use the ":target" CSS pseudo-class on an element with a message?
- yakshaving_jgt 5y agoI don't think so. I think the form needs to still point to the URI which is expecting the POST request. Maybe I'm not imagining hard enough, but I don't think this approach will work. Furthermore, according to this article[0], the `:target` approach is viable when it's acceptable to change the browser history, whereas in my case that is exactly what I'm trying to avoid. [0]: https://css-tricks.com/css-target/ https://css-tricks.com/css-target/
- SketchySeaBeast 5y ago> Maybe I'm not imagining hard enough, but I don't think this approach will work. I've never heard this turn of phrase before, but I really like it.
- donatj 5y agoIn my general use, often it was cases where you either didn’t need to or just some minor `:active` styling was enough. We also did just use some JS to for instance hide the button. Our goal wasn't to avoid JS perse, just AJAX wasn't really a thing yet.
- phil294 5y agoI can't think of a solution to this either, but there are also other ways of doing non-refreshing requests sending by toggling background-images, loading=lazy <img> and so on
- yakshaving_jgt 5y agoThere is the risk however of getting a bit too clever with this, and violating the principle of least astonishment.