refactored main.js jquery ajax call to run through one function