Skip to content

Instantly share code, notes, and snippets.

@yoshifumi0521
Created January 10, 2013 00:31
Show Gist options
  • Save yoshifumi0521/4498330 to your computer and use it in GitHub Desktop.
Save yoshifumi0521/4498330 to your computer and use it in GitHub Desktop.
RailsでのAjax処理。非同期通信をして、クライアントでにコールバックする。
// view/member/index.html.erb
<%= form_for @member,:remote => true,:html => {:id => 'form'} do |form| %>
//フォーム
<%= form.submit "送信" %>
<% end %>
<scritp>
$(function(){
//Ajax処理
$("#form").
.live("ajax:beforeSend", function(e,data,status,xhr){
//ajax通信の送信時の処理
}
.live("ajax:success", function(e,data,status,xhr){
//ajax通信の成功時の処理
}
.live("ajax:error", function(e,data,status,xhr){
// ajax通信失敗時の処理
}
.live("ajax:complete", function(e,xhr,status){
// ajax通信完了時の処理
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment