Factor out an XHR-downloading function