我有一个适用于 html 的表单,我正在尝试将其转换为 ajax。这是我的代码,我认为问题在于我的表单没有提交 ajax 请求,它仍在发送正常的 html 请求。我得到了一个带有部分的新页面(项目/创建)。如何解决这个问题?
<%= form_tag ( :action => :create, :remote => true, :method => :post ) do %>
... #stuff
<% end %>
控制器 -
def create
...
respond_to do |format|
format.html { render :partial => 'view_item', :item_num => @t[:item_num], :flag => "new" }
format.js
end
end
JS-
# cat view.js.erb
$('#item').html(<%= (render :partial => 'view_item').to_json.html_safe %>); #I have "item" div in my view
日志 -
Started POST "/item/create" for 10.10.23.12 at 2012-04-18 06:41:23 -0400
Processing by ItemController#create as HTML
Parameters: {"utf8"=>"â", "authenticity_token"=>"GRNJAx2ePzRIOaJjr2w4F6WwueRq7FL9tIDaKtIPZSQ=",
.......#long log here
"
(0.1ms) COMMIT
Rendered item/_view_item.html.erb (1.6ms)
Completed 200 OK in 3261ms (Views: 2.4ms | ActiveRecord: 4.1ms)