M
M
Meehailo2021-09-14 13:17:28
CoffeeScript
Meehailo, 2021-09-14 13:17:28

How to display text in CoffeeScript on button click?

I have an application on ruby ​​on rails, a button is rendered in an erb file, a click on it is processed in a coffee script. tell me how to make it so that when you click on the button (it sends a request - already implemented), this button disappears, and in its place a text appears with the received response to the request?

$('#send').on 'click', (e) ->
    blockId = $(this).data('id')["$oid"]
    $.ajax(
      url: 'send',
      type: "get",
      data: { block_id: blockId }
    )
    $(this).text('Отправлено')


<%= button_tag 'Отправить', class: 'btn btn-primary', id: 'send',
                  type: 'button' , remote: true, data: { id: form_builder.object.id } %>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question