Refactor AJAX util to allow headers and data

Also added a bunch of tests for request() and the support util.