Ajax introduction (1)

Ajax:

  • using javascript to make a request to server
  • fast when used correctly because partial page is refreshed
  • lost addressibility ( two actions may have the same URL )

JQuery:

  • a lib of javascript
  • support Ajax
  • more convienent than the rails’ lib Prototype and (***) for Ajax

JQuery syntax:

  • run on click: $(‘some_tag’).click(function(){})
  • run on submit: $(‘some_tag’).click( function() {} )
  • add stuff on a page: $(‘some_html_tag’).append();
  • with Ajax

$.ajax({

data: {

attr_name:  this.xxxselect.val()   // rails got the data by params[:attr_name] (which

// should equal to user’s selected value this.xxxselect.val() here)

}

success: function() {

}

error:  function() {

}

});

Good slides: http://www.slideshare.net/JamesEdwardGrayII/ajax-with-jquery-in-rails

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s