这是我目前使用的代码:如何将函数应用于jquery ajax提交完成的类?
$.ajax({
success: function(){
$('.post_container').append('test <br />');
}
});
<% sleep 1 %>
有使用同一类别中的几种意见,所以测试是它类似于我用我的单个主窗体微柱的代码,但与此适用于所有post_containers,而不是邮件刚刚制作的那个。 “测试”文本最终将被保存用户发布的实际评论的div替换。
通常我会使用“this”,但这不起作用。
HTML:
<div class="post_content">
<div class="post_container">
<div class="userNameFontStyle">
<%= link_to current_users_username.capitalize, current_users_username %> -
<div class="post_time">
<%= time_ago_in_words(m.created_at) %> ago.
</div>
</div>
<%= simple_format h(m.content) %>
</div>
<% if m.comments.any? %>
<% comments(m.id).each do |comment| %>
<div class="comment_container">
<%= link_to image_tag(default_photo_for_commenter(comment), :class => "commenter_photo"), commenter(comment.user_id).username %>
<div class="commenter_content">
<div class="userNameFontStyle">
<%= link_to commenter(comment.user_id).username.capitalize, commenter(comment.user_id).username %> - <%= simple_format h(comment.content) %>
</div>
</div>
<div class="comment_post_time">
<%= time_ago_in_words(comment.created_at) %> ago.
</div>
</div>
<% end %>
<% end %>
<% if logged_in? %>
<%= form_for @comment, :remote => true do |f| %>
<%= f.hidden_field :user_id, :value => current_user.id %>
<%= f.hidden_field :micropost_id, :value => m.id %>
<%= f.text_area :content, :placeholder => 'Post a comment...', :class => "comment_box", :rows => 0, :columns => 0 %>
<div class="commentButtons">
<%= f.submit 'Post it', :class => "commentButton" %>
<div class="cancelButton">
Cancel
</div>
</div>
<% end %>
<% end %>
</div>
</div>
我将如何面对呢?
亲切的问候
你能澄清你想要发生什么吗?你的代码不工作?您没有指定实际拨打电话的网址。 – Seth 2012-04-11 00:13:58
是否像'$('。post_container')。submit(...)' – 2012-04-11 00:14:55
我想简单地将新评论追加到评论列表中。我在Rails框架中使用ruby,大部分的ajax都是通过在表单中加入“remote => true”来设置的。有了上面的代码,如果ajax文章提交成功,那么我想将评论附加到评论列表。上面的代码附加到页面上的所有.post_container类,而不仅仅是我发布新评论的那个类。 – LondonGuy 2012-04-11 00:24:48