Rail 3 에서 ajax 가 Form 을 제출 하 는 쓰기 (JQuery)

2093 단어 jqueryAjaxBlogRails
회전: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 %>

좋은 웹페이지 즐겨찾기