Improve AJAX setup to use XDR only when necessary