move AJAX javascript code into application.js

move AJAX javascript code into application.js
and add to handle web history