diff --git a/core/misc/ajax.js b/core/misc/ajax.js --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -256,19 +256,23 @@ ajax.options.data.dialogOptions = elementSettings.dialog; } - if (ajax.options.url.indexOf('?') === -1) { - ajax.options.url += '?'; - } else { - ajax.options.url += '&'; - } - var wrapper = "drupal_".concat(elementSettings.dialogType || 'ajax'); if (elementSettings.dialogRenderer) { wrapper += ".".concat(elementSettings.dialogRenderer); } - ajax.options.url += "".concat(Drupal.ajax.WRAPPER_FORMAT, "=").concat(wrapper); + var queryParameter = Drupal.ajax.WRAPPER_FORMAT + '=' + wrapper; + if (ajax.options.url.indexOf(Drupal.ajax.WRAPPER_FORMAT) === -1) { + // Ensure that we have a valid URL by adding ? when no query parameter is + // yet available, otherwise append using &. + ajax.options.url += (ajax.options.url.indexOf('?') === -1) ? '?' : '&'; + ajax.options.url += queryParameter; + } else { + var regexPattern = new RegExp(Drupal.ajax.WRAPPER_FORMAT + '=[^&]*', 'i'); + ajax.options.url = ajax.options.url.replace(regexPattern, queryParameter); + } + $(ajax.element).on(elementSettings.event, function (event) { if (!drupalSettings.ajaxTrustedUrl[ajax.url] && !Drupal.url.isLocal(ajax.url)) { throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', { @@ -671,4 +675,4 @@ messages.add(response.message, response.messageOptions); } }; -})(jQuery, window, Drupal, drupalSettings, window.tabbable); \ No newline at end of file +})(jQuery, window, Drupal, drupalSettings, window.tabbable); diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -569,19 +569,22 @@ ajax.options.data.dialogOptions = elementSettings.dialog; } - // Ensure that we have a valid URL by adding ? when no query parameter is - // yet available, otherwise append using &. - if (ajax.options.url.indexOf('?') === -1) { - ajax.options.url += '?'; - } else { - ajax.options.url += '&'; - } // If this element has a dialog type use if for the wrapper if not use 'ajax'. let wrapper = `drupal_${elementSettings.dialogType || 'ajax'}`; if (elementSettings.dialogRenderer) { wrapper += `.${elementSettings.dialogRenderer}`; } - ajax.options.url += `${Drupal.ajax.WRAPPER_FORMAT}=${wrapper}`; + + const queryParameter = `${Drupal.ajax.WRAPPER_FORMAT}=${wrapper}`; + if (ajax.options.url.indexOf(Drupal.ajax.WRAPPER_FORMAT) === -1) { + // Ensure that we have a valid URL by adding ? when no query parameter is + // yet available, otherwise append using &. + ajax.options.url += ajax.options.url.indexOf('?') === -1 ? '?' : '&'; + ajax.options.url += queryParameter; + } else { + const regexPattern = new RegExp(`${Drupal.ajax.WRAPPER_FORMAT}=[^&]*`, 'i'); + ajax.options.url = ajax.options.url.replace(regexPattern, queryParameter); + } // Bind the ajaxSubmit function to the element event. $(ajax.element).on(elementSettings.event, function (event) {