How to make get_theme_mod work with AJAX in the customizer preview

There is a bug in WordPress 4.8.2 which causes pending customized changes to not be injected into Ajax requests in the preview. This has been fixed in 4.9-alpha via #42162. In the mean time, however, you can do a workaround to modify the requested url with logic like:

// Workaround defect introduced in WordPress 4.8.2 where preview nonce is not included in request.
if ( 'undefined' !== typeof _wpCustomizeSettings ) {
    urlParser = document.createElement( 'a' );
    urlParser.href = url;
    urlParser.search += '&customize_preview_nonce=" + _wpCustomizeSettings.nonce.preview;
    url = urlParser.href;
}