使用RJS替换div
我目前有一个链接,单击该链接会调用一个 JavaScript 函数,该函数会收集一些数据,然后使用 ProtoType 提交表单...
function myFunction(){
data = someobject.getData();
$('myform').request({
parameters: {data:data, id:id,},
onSuccess: function(transport) {
document.location.reload();
}
});
}
...
<%= form_tag({:controller => "data", :action => "process"}, :id => "myform") %></form>
请注意我的非 AJAXy document.location.reload(); 在 onSuccess 回调中。
我希望 DataController#process 执行此操作...
def process
...
render :update do |page|
page.replace 'my_div', :partial => 'test'
end
end
任何人都可以指导我在调用 JavaScript 时需要更改哪些内容才能使 page.replace 工作吗? 当然,现在它只是被忽略了。
我尝试了各种方法,并四处阅读,但在这种情况下我没有得到我需要做的事情。
谢谢
I currently have a link which when clicked calls a JavaScript function, which gathers some data and then uses ProtoType to submit a form...
function myFunction(){
data = someobject.getData();
$('myform').request({
parameters: {data:data, id:id,},
onSuccess: function(transport) {
document.location.reload();
}
});
}
...
<%= form_tag({:controller => "data", :action => "process"}, :id => "myform") %></form>
Notice my very unAJAXy document.location.reload(); in the onSuccess callback.
I want DataController#process to do this...
def process
...
render :update do |page|
page.replace 'my_div', :partial => 'test'
end
end
Can anyone guide me as to what I need to change in the calling JavaScript for page.replace to work? Right now of course, it just gets ignored.
I've tried various things, and read around, but I'm not getting what I need to do in this situation.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将渲染从控制器中取出并将其放入views/datas/process.js.rjs
Take the rendering out of the controller and put this in views/datas/process.js.rjs
您可以将 form_for 更改为:
然后在控制器中渲染部分,它将用它更新“my_form”:
You could change your form_for to this:
And then render the partial in the controller and it will update 'my_form' with it:
我不确定你到底希望它如何工作,但有一个
remote_form_for
标签将为您执行请求。 另外,您可能希望查看下面的链接,了解使用 RJS 模板的示例:http ://www.developer.com/lang/article.php/3668331
I'm not sure exactly how you want it to work, but there is a
remote_form_for
tag that will do the request for you. Also, you may wish to look at the link below for an example on using RJS templates:http://www.developer.com/lang/article.php/3668331
感谢您的所有建议 - 这就是我最终所做的:
在 DataController#process 中执行此操作...
(章节 - 我会将其部分放置!)
Thanks for all suggestions - here's what I ended up doing:
In DataController#process to do this...
(chap - I'll put this in partial!)