六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 31|回复: 0

Rail3下 ajax提交Form的写法(JQuery)

[复制链接]

升级  88%

50

主题

50

主题

50

主题

秀才

Rank: 2

积分
182
 楼主| 发表于 2013-1-29 10:45:28 | 显示全部楼层 |阅读模式
转: 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 %>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表