mercredi 25 mars 2015

AJAX success response not working Rails

I have a mailer that is successfully sending using AJAX, but when the submit button is clicked, it is left depressed and no success message is displayed. Clicking the button multiple times results in multiple form submissions. The button should reset, and (from my understanding) the AJAX:success event should generate some sort of text to show it was successful.


The AJAX Script (from rails guides)



<script>
$(document).ready ->
$("#AJAX-form").on("ajax:success", (e, data, status, xhr) ->
$("#AJAX-form").append xhr.responseText
).on "ajax:error", (e, xhr, status, error) ->
$("#AJAX-form").append "<p>ERROR</p>"
</script>


The form:



<%= form_tag("/pages/thank_you", remote: true, class: 'AJAX-form') do %>
<div class="row">
<div class="col-md-2">
<div class="input-group">
<%= text_field_tag :name, nil, class: 'form-control', placeholder: 'Name' %>
</div>
</div>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<%= text_field_tag :email, nil, class: 'form-control', placeholder: 'Email' %>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<div class="input-group text-area-wide">
<%= text_area_tag :message, nil, class: 'form-control text-area-wide', placeholder: 'Message' %>
</div>
</div>
</div>
<br>
<%= submit_tag 'Send Message', class: 'btn btn-success' %>
<% end %>


The controller action:



def thank_you
@name = params[:name]
@email = params[:email]
@message = params[:message] || "Hello!"
UserMailer.contact_form(@email, @name, @message).deliver
end

Aucun commentaire:

Enregistrer un commentaire