Rail3下 ajax提交Form的写法(JQuery)
转: http://www.alfajango.com/blog/rails-3-remote-links-and-forms/<script type="text/javascript"> //处理ajax回调函数 $(function() { // ajax:before // fires before the request starts, provided a URL was provided in href or action // ajax:loading// fires after the AJAX request is created, but before it's sent // ajax:success// fires after a response is received, provided the response was a 200 or 300 HTTP status code // ajax:failure// fires after a response is received, if the response has a 400 or 500 HTTP status code // ajax:complete // fires after ajax:success or ajax:failure // ajax:after // fires after the request events are finished $('#ajax_form').bind('ajax:success', function(evt, xhr, settings) { alert(xhr.username); alert(xhr.password); }); });</script><%= form_tag "/layer/ajax_form", :id=>'ajax_form', :remote=>true, :method =>:post do %> <%= label_tag :username, '用户名' %> <%= text_field_tag :username %> <%= label_tag :password, '密码' %> <%= password_field_tag :password %> <%= submit_tag '提交请求' %><% end %><h1>改善下</h1><h3>使用 url_for 查找Url<%= url_for(:controller => 'layer', :action => 'ajax_form') %></h3><%= form_tag url_for(:controller => 'layer', :action => 'ajax_form'), :id=>'ajax_form_2', :remote=>true, :method => :post do %> <%= label_tag :username, '用户名' %> <%= text_field_tag :username %> <%= label_tag :password, '密码' %> <%= password_field_tag :password %> <%= submit_tag '提交请求' %><% end %>
页:
[1]