Rails 3/JQuery 表单在页面上重复

发布于 2024-10-26 13:59:38 字数 761 浏览 5 评论 0原文

我有一个看起来与此类似的表单 -

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情独悲 2024-11-02 13:59:38

您在请求/响应中的哪里遇到问题?您是否确认表单已提交但没有回复?

您是否使用 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?

花开柳相依 2024-11-02 13:59:38

遗憾的是,(或者不遗憾?)这个错误并不存在于我的代码中。 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文