From 0a94ab7dd43e778b3199ed115a6409093785c96d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 29 Apr 2014 20:01:36 -0700 Subject: [PATCH] CRM-14215 - Fix ajax redirects --- CRM/Utils/System.php | 9 +++++++++ js/crm.ajax.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 7e5908bbde..ec5a76f9df 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -391,6 +391,15 @@ class CRM_Utils_System { // replace the & characters with & // this is kinda hackish but not sure how to do it right $url = str_replace('&', '&', $url); + + // If we are in a json context, respond appropriately + if (CRM_Utils_Array::value('snippet', $_GET) === 'json') { + CRM_Core_Page_AJAX::returnJsonResponse(array( + 'status' => 'redirect', + 'userContext' => $url, + )); + } + header('Location: ' . $url); self::civiExit(); } diff --git a/js/crm.ajax.js b/js/crm.ajax.js index a13d5dec4e..066269b15a 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -364,7 +364,7 @@ $el.crmSnippet('option', 'block') && $el.unblock(); $el.trigger('crmFormSuccess', response); // Reset form for e.g. "save and new" - if (response.userContext && settings.refreshAction && $.inArray(response.buttonName, settings.refreshAction) >= 0) { + if (response.userContext && (response.status === 'redirect' || (settings.refreshAction && $.inArray(response.buttonName, settings.refreshAction) >= 0))) { // Force reset of original url $el.data('civiCrmSnippet')._originalUrl = response.userContext; $el.crmSnippet('resetUrl').crmSnippet('refresh'); -- 2.25.1