Added js to footer
Moved ajax to new function