I’m a big fan of using Rails UJS, it’s a really nice way to handle 90% of the things I need to do by sprinkling a little bit of extra markup into my HTML.
I recently needed to make an AJAX call within a stimulus controller. Initially I looked at using the Fetch API, however I needed to support IE & wanted an easy way to include CSRF Protection.
In the past I’ve been able to use
Here is the code I ended up with to get it working: