Rails 3/JQuery 表单在页面上重复
我有一个看起来与此类似的表单 -
<Form (Unique Form ID) (Common Form Class)>
Some Value: <select_list_element> <submit_button> <image_tag_for_progress_indicator>
<Form Close Tag>
非常简单 - 在页面上重复 20 次。基本目的是让用户浏览表单列表,一次性更新值,然后继续。
为了让它更好一点,我通过 AJAX 进行提交,并希望允许指示正在更新的内容。然而,我似乎无法让它正常工作 - 这是我正在使用的 javascript:
$('(Common Form Class)')
.bind('ajax:loading', function(){ $(this).find('(image tag class').attr('src', '(spinning gif)'); })
.bind('ajax:success', function(){ $(this).find('(image tag class').attr('src', '(success gif)'); })
.bind('ajax:failure', function (){ $(this).find('(image tag class').attr('src', '(failure gif)'); })
我 99% 肯定我错误地使用了“this” - 但我似乎无法调试原因。
I have a form that looks similar to this -
<Form (Unique Form ID) (Common Form Class)>
Some Value: <select_list_element> <submit_button> <image_tag_for_progress_indicator>
<Form Close Tag>
Pretty straight forward - repeat 20x for the page. The basic purpose is to let users go down the form list, update values on a one off, and then move on.
To make it a little nicer, I'm doing the submission via AJAX, and wanted to allow for indicating things were updating. However, I can't seem to get it to work right - here's the javascript I'm using:
$('(Common Form Class)')
.bind('ajax:loading', function(){ $(this).find('(image tag class').attr('src', '(spinning gif)'); })
.bind('ajax:success', function(){ $(this).find('(image tag class').attr('src', '(success gif)'); })
.bind('ajax:failure', function (){ $(this).find('(image tag class').attr('src', '(failure gif)'); })
I'm 99% positive that I'm getting the use of "this" wrong - but I can't seem to debug why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在请求/响应中的哪里遇到问题?您是否确认表单已提交但没有回复?
您是否使用 Rails 3 预打包的 UJS (rails.js) 来帮助提交表单?
另外,您如何知道根据 AJAX 结果更新哪个表单?
Where in the request/response are you having trouble? Have you confirmed the form submits but no response comes back?
Are you using the Rails 3-prepackaged UJS (rails.js) to aid in submitting the form?
Also, how do you know which form to update upon the AJAX result?
遗憾的是,(或者不遗憾?)这个错误并不存在于我的代码中。 Rails 人员决定更新 UJS 事件,现在“ajax:loading”不再正确 - 现在是“ajax:beforeSend”,并且所有教程都是错误的。
希望有人看到这一点并能够纠正自己的代码。
这是一个正确的教程:
http://www. alfajango.com/blog/rails-3-remote-links-and-forms/
Sadly, (or not sadly?) the bug was not with my code. The rails guys decided to update the UJS events, and now "ajax:loading" is no longer correct - it's now "ajax:beforeSend", and all the tutorials out there are wrong.
Hope someone sees this and is able to correct their own code.
Here's a tutorial that has it correct:
http://www.alfajango.com/blog/rails-3-remote-links-and-forms/