使用 mootools 实现不显眼的 JavaScript ajax?
MVC3 中提供了带有 jQuery 的不显眼的 JavaScript。但是如何将不显眼的 Javascript ajax 与 mootools 一起使用呢?
Unobtrusive JavaScript with jQuery is available in MVC3.But how can I use the unobtrusive Javascript ajax with mootools?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这很简单。看看最近发布的 http://mootools.net/blog/2011 /12/20/mootools-behavior/,我认为它支持它。
我也在我的 Modal.BootStrap 中使用了这种方法(在 github 上查看源代码,链接在那里)它使用数据属性从 ajax 资源获取数据,虽然不太一样,但它确实是一个开始。
我只花了 10 分钟来做这个,这是一个好的开始:
http://jsfiddle.net/dimitar/zYLtQ/< /a>
适用于以下 DOM:
您应该能够在此基础上进行构建。在重构时,我会将请求事件移至它们自己的方法中,并添加一些更多的校对等,但这很好。我不知道 mvc 的所有功能,但缺少一件事是表单验证事件。我还添加了一个自定义事件,完成后会触发,以便您的 ajaxifier 实例可以执行该表单特有的操作(请参阅 data-event-success="contactFormSuccess")
,它还可以使用默认请求选项,如果没有隐式指定,甚至创建什么请求对象 - Request、Request.HTML、Request.JSON 等。像 onRequest、spinners 等事件也是可行的...我认为你只需要按照 mvc 提供的选项进行操作即可构建它们以开始使用。
yeah, this is trivial to do. have a look at the recently released http://mootools.net/blog/2011/12/20/mootools-behavior/, I think it supports it.
I have used this approach in my Modal.BootStrap (view source on github, link's there) as well whereby it uses data attributes to fetch data from an ajax resource, it's not quite the same but it certainly is a start.
I just spent 10 mins making this and it's a good start:
http://jsfiddle.net/dimitar/zYLtQ/
works with a DOM of:
you should be able to build on that. on refactor i'd move the request events into their own methods and add some more proofing etc but it's fine. i don't know all mvc does but one thing that is missing is form validation events. i also added a custom event that is fired when done so your ajaxifier instance can do something particular to that form (see
data-event-success="contactFormSuccess"
)also, it can use default request options if not implicitly specified, even what request object to create - Request, Request.HTML, Request.JSON etc. Events like onRequest, spinners etc are also feasible... I think you just need to work your way through the options that mvc provides and build them to get started.