JS function for handling ajax calls

This is being imported from another project and will
need some changes/updates.