English 中文(简体)
铁路3号,处理麻风反应
原标题:Rails 3, handling ajax response

我在“铁路”3号上使用Ruby,有一页,有一份评论清单,我希望在用户发表评论时,用Ajax显示一种形式。

迄今为止,我有一份部分名称为_form_comment.html.erb和html。 这一点没有问题。

认为,这是reply纽扣吨的代码:

link_to "Reply", {:controller => "catalog", :action => "form_comment", :id => c.id}, :remote => true, :class => "btn_reply_comment"

在控制人员中,我补充说,每当一个reply纽芬兰文时,就将部分内容归还:

def form_comment
    if request.xhr?
        render:partial => "form_comment"
    end
end

And, in order to "do something" with the response, I have this script

$(document).ready(function(){
    $(".btn_reply_comment")
        .bind("ajax:success", 
              function() { alert("Ajax response"); });
});

当我发布reply纽顿时,我可以使用“火焰”检查,“Ajax”申请正在退回“<0>304条不修改的。 我在阅读了其他一些线索时说,我应当根据亚克斯的请求解脱海滩,但鉴于Im没有人工使用<代码>$.ajax.,我不知道如何修改。

我能做些什么?

最佳回答

我认为,你必须参加“黑轴:成功”活动,其形式是联系人,而不是联系人。

so try to bind to:

".btn_reply_comment form"

Anyway I suggest using a normal link_to or "a" element, and some jquery code to make the ajax request and handle the callback like:

$(".btn_reply_comment").on("click", function(){
   $.get($(this).attr("href"), function(data){
     eval(data)
   })
})

页: 1

问题回答

暂无回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签