我一直在到处找,不明白为什么这不起作用。
我正在尝试测试一个非常基本的ajax操作。这是我的代码:
控制器:
def commit
respond_to do |format|
format.html { redirect_to :action => "index" } # see note 1
format.js { render :layout => false } # see note 2
format.js { render :nothing => true }
end
end
看法
<%= link_to "commit", :action => "commit", :remote => true %>
<%= form_tag( :action => "commit", :remote => true, :method => :post) do %>
<%= submit_tag "commit" %>
<% end %>
<div id= message ></div>
commit.js.erb
console.log( committed );
$( #message ).html("committed");
The problem is I d get to the commit method, but the page would reload, which defeats the point of remote=>true Also the commit.js never seemed to get called.
Note 1: If I exclude this line, I get the blank page to /commit. Including it makes the page just reload
Note 2: I ve tried both of these approaches suggested by other SO posts
Note 3: I ve tried both using link_to and form_tag
有人能帮忙吗?谢谢