Simplify AJAX redirect
This commit is contained in:
parent
4a5eb8b408
commit
fdea1970d0
|
@ -14,9 +14,6 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
||||||
$title_page = $title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name();
|
$title_page = $title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name();
|
||||||
if (is_ajax()) {
|
if (is_ajax()) {
|
||||||
header("X-AJAX-Title: " . rawurlencode($title_page));
|
header("X-AJAX-Title: " . rawurlencode($title_page));
|
||||||
if ($_GET["ajax"]) {
|
|
||||||
header("X-AJAX-Redirect: " . remove_from_uri("ajax"));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$protocol = ($HTTPS ? "https" : "http");
|
$protocol = ($HTTPS ? "https" : "http");
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -371,7 +371,7 @@ function auth_url($driver, $server, $username) {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function is_ajax() {
|
function is_ajax() {
|
||||||
return ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" || $_GET["ajax"]);
|
return ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Send Location header and exit
|
/** Send Location header and exit
|
||||||
|
@ -388,7 +388,7 @@ function redirect($location, $message = null) {
|
||||||
if ($location == "") {
|
if ($location == "") {
|
||||||
$location = ".";
|
$location = ".";
|
||||||
}
|
}
|
||||||
header("Location: $location" . (is_ajax() ? (strpos($location, "?") !== false ? "&" : "?") . "ajax=1" : ""));
|
header((is_ajax() ? "X-AJAX-Redirect" : "Location") . ": $location");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,9 +194,12 @@ function ajax(url, callback, data) {
|
||||||
xmlhttp.onreadystatechange = function () {
|
xmlhttp.onreadystatechange = function () {
|
||||||
if (xmlhttp.readyState == 4) {
|
if (xmlhttp.readyState == 4) {
|
||||||
var redirect = xmlhttp.getResponseHeader('X-AJAX-Redirect');
|
var redirect = xmlhttp.getResponseHeader('X-AJAX-Redirect');
|
||||||
if (redirect && history.replaceState) {
|
if (redirect) {
|
||||||
|
if (history.replaceState) {
|
||||||
history.replaceState(null, '', redirect);
|
history.replaceState(null, '', redirect);
|
||||||
}
|
}
|
||||||
|
return ajaxSend(redirect);
|
||||||
|
}
|
||||||
var title = xmlhttp.getResponseHeader('X-AJAX-Title');
|
var title = xmlhttp.getResponseHeader('X-AJAX-Title');
|
||||||
if (title) {
|
if (title) {
|
||||||
document.title = decodeURIComponent(title);
|
document.title = decodeURIComponent(title);
|
||||||
|
|
Loading…
Reference in a new issue