开发者

Everything works in this Ajax submission except for the notice

The email still gets sent and delivered, but still no flash message.

form:

    <%= form_for :fb_comment, :url => update_reply_feedback_path, :html => { :id => "reply" }, :remote => true do |f| %>
        <%= f.text_area :reply, :size => '66x7' %><br>
        <center><%= f.submit "Send Reply"  %></center>
    <% end %>

in the layout file:

<%- flash.each do |name, msg| -%>
   <%= content_tag :div, msg, :id => "flash_#{name}" %>
<%- end -%>

in controller:

def reply2_feedback
   ...
   flash.now[:notice] = 'Reply was successfully sent.'
   respond_to do |format|
      format.html {}
      format.js
   end 
end

in application.js:

jQuery.ajaxSetup({
   'beforeSend': function(xhr) {xhr.setRequestHeader("Ac开发者_如何学运维cept", "text/javascript")}
})

$(document).ready(function() {
   $("#reply").submit(function() {
      $.post($(this).attr("action"), $(this).serialize(), null, "script");
      return false;
   })
})

update_reply.js.erb:

$("#flash").html('<div class="notice_alert"><%= escape_javascript(flash.delete(:notice)) %></div>');

Thank you.


Try using

flash.now[:notice] = 'Reply was successfully sent.'

instead.


After 58 views without a solution i decided to cave to meet the pressure of a deadline and settle for second best by adding a simple alert to the javascript. If anyone does happen upon this question and provides a solution that makes the flash message work, then i'll switch the answer to you. Thanks to those who gave it a shot.

$(document).ready(function() {
    $("#reply").submit(function() {
        $.post($(this).attr("action"), $(this).serialize(), null, "script");
        alert("Your reply was emailed.");
        return false;
    })
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜