<input type="button" name="load" value="Reload page" 


The reload() method reloads the current page displayed in the browser.

It is good to use when you update some data after success calling ajax and want

to show users the update.

Javascript notes

  • Functions are normally used in combination with events.
  • document:Each web page loaded in the browser has its own document object. This object serves as an entry point to the web page’s content (the DOM tree, including elements such as <body> and <table> ) and provides functionality global to the document (such as obtaining the page’s URL and creating new elements in the document)。 SEE HERE
  • Define a new Data Type,

function TypeName( [args] ) { this.args = args; }

it uses keyword function to define datatype TypeName. Its constructor uses optional arguments. And these attributes can be obtained by var myType=new TypeName(name); Document.write(myType.name).

Note that in JS, there is no conception of class.

  • define a new variable by defining a function: it actually defines a new object

var a_obj = new function(param1, param2)



Parameter URL in Ajax of jquery

I am always wondering where the request will be sent after calling ajax; i.e., after the ajax action, what controller/action in Rails will be called.


jQuery.ajax( url [, settings] )

Default: The current page

A string containing the URL to which the request is sent.

when calling ajax, url is a string the request going to. When there is no value, it will be the current page by default.

Ajax introduction (1)


  • 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 )


  • 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


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