Answer the question
In order to leave comments, you need to log in
Why does this alert pop up after submitting the form?
Good afternoon.
There is a form:
= form_for :callback_profile_params,
:url => { :controller => 'users', :action => 'callback_profile' },
:method => 'POST',
:remote => true,
html: { id: 'callback_profile', :class => 'send-form' } do |f|
= hidden_field_tag :authenticity_token, form_authenticity_token
= f.text_field :user_id, :type => 'hidden', :value => current_user.id
.form-group
= f.text_field :title, :placeholder => 'Тема обращения'
.form-group
= f.text_area :message, :placeholder => 'Вопрос'
= submit_tag 'Отправить', :class => 'btn btn-primary', :id => 'btn_submit'
$ ->
$("#callback_profile").on("ajax:success", (e, data, status, xhr) ->
$("#btn_submit").replaceWith data
).on "ajax:error", (xhr, status, error) ->
$("#btn_submit").replaceWith data
before_action :authenticate_user!
def callback_profile
render :text => 'Запрос успешно прошел.'
end
Answer the question
In order to leave comments, you need to log in
Firstly, in the 'ajax:error' error handler, the data variable is not set
Secondly, try to do this
def callback_profile
render json: { text: 'Запрос успешно прошел.'}
end
$ ->
$("#callback_profile").on("ajax:success", (e, data, status, xhr) ->
$("#btn_submit").replaceWith data['text']
).on "ajax:error", (xhr, status, error) ->
$("#btn_submit").replaceWith 'Error!'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question