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 %>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值