mysql,Linux,HighPerformance,ruby on Rails

2010年8月3日星期二

Rails3使用jquery rjs,可能需要注意的地方。mark

这里假设你使用rails3, jquery rails.js

你想实现ajax loading效果,却发现rails的tag里只使用:remote => true
并没有rails2里使用的loading函数。
我看了rails.js,看到

The UJS drivers trigger six events on every AJAX call:

  • ajax:before
  • ajax:loading
  • ajax:success
  • ajax:failure
  • ajax:complete
  • ajax:after
但是怎么使用是个问题。
看了这个ticket,就知道并不是所有人了解:
https://rails.lighthouseapp.com/projects/8994/tickets/4486-new-ujs-helpers-do-not-have-a-way-to-render-a-loading-text-icon
his can easily be accomplished each driver has a custom callback that fires before the request is sent, here is an example using the jQuery driver.
  $('#new_resource').live('ajax:loading', function() {
// code to display loading div
});


refs:
https://rails.lighthouseapp.com/projects/8994/tickets/4486-new-ujs-helpers-do-not-have-a-way-to-render-a-loading-text-icon
http://www.slideshare.net/adamlogic/jquery-and-rails-sitting-in-a-tree
http://code.alexreisner.com/articles/link-to-remote-with-ujs.html

没有评论:

发表评论