我有一个通过 ajax 成功提交数据的表单,但我不知道如何在 ajax 操作之后触发事件。提交新记录后,我想重新加载包含表单的部分。
看法
#container
#partial
<%= form_for [@qa, @newpdd], :remote => true do |f| %>
....
<%= f.submit "add %>
PDD 控制器
def create
@pdd = Pdd.create!(params[:pdd])
@pdd.qa_id = params[:qa_id]
@qa = Qa.find(params[:qa_id])
respond_to do |format|
if @pdd.save
format.html { redirect_to(@qa, :notice => 'Pdd was successfully created.') }
format.xml { render :xml => @pdd, :status => :created, :location => @pdd }
format.js
# render :partial => pddsection
else
format.html { render :action => "new" }
format.xml { render :xml => @pdd.errors, :status => :unprocessable_entity }
end
end
end
创建.js.erb
$('#partial').replaceWith("<%= escape_javascript(render :partial => 'pdds/partial') %>");
有任何想法吗?