[Feature] Allow data-params for ujs links that don't have data-remote="true"

41 views
Skip to first unread message

sternenseemann

unread,
Mar 25, 2020, 11:11:54 PM3/25/20
to Ruby on Rails: Core
Hi all,

I noticed there is no simple way to send synchronous requests using rails ujs that have a request body. At the moment there is either the possibility to send an AJAX request with a link like <a data-method="PUT" data-remote="true" data-params="data=param" …> or a synchronous request without a request body like this: <a data-method="DELETE">…

My proposal is to make the data-method handler check the data-params field and add the data that is specified there to the temporary form that is created in order to send the request. I already have a version of this that works here.

The only downside of my implementation is that it only supports urlencoded form data in the data-params field currently. I want to add support for JSON, but I am a bit confused by the data-type field: I checked in the implementation of ajax() where dataType only seems to influence the Accept-Headers. So my question is: Is data-type intended to specify the type of the request or the response or both? The documentation indicates that it is about the type of data-type and I'd really like to use this field to detect the type of the data stored in data-params, since I'm not really fancying autodetecting that. Of course there can only be a limited number of supported formats since we can't send arbitrary request bodies using forms as opposed to using XMLHttpRequest.

I'd love to here your feedback and suggestions on this!

Cheers,

Lukas
Reply all
Reply to author
Forward
0 new messages