Don't send a location header if we currently handle an ajax response/request - use the corresponding json function instead. Doing this on the server side is neccessary as the location header is one of the few ones which is handled by the browser before any XMLHttpRequest event is fired (according to W3C specification)

This commit is contained in:
Andreas Stöckel 2011-06-11 21:27:15 +00:00
parent 220af27f60
commit 49ece38c6c
3 changed files with 43 additions and 3 deletions

View File

@ -480,6 +480,9 @@ class egw extends egw_minimal
$iis = @strpos($GLOBALS['HTTP_ENV_VARS']['SERVER_SOFTWARE'], 'IIS', 0);
// Determines whether the current output buffer should be flushed
$do_flush = true;
if(!$url)
{
$url = $_SERVER['PHP_SELF'];
@ -492,6 +495,14 @@ class egw extends egw_minimal
echo "<H3>Please continue to <a href=\"$url\">this page</a></H3>";
echo "\n</BODY></HTML>";
}
else if (egw_json_response::isJSONResponse() || egw_json_request::isJSONRequest())
{
$response = egw_json_response::get();
$response->redirect($url);
// If we are in a json request, we should not flush the current output!
$do_flush = false;
}
else
{
if (headers_sent($file,$line))
@ -501,7 +512,11 @@ class egw extends egw_minimal
Header("Location: $url");
print("\n\n");
}
@ob_flush(); flush();
if ($do_flush)
{
@ob_flush(); flush();
}
// commit session (if existing), to fix timing problems sometimes preventing session creation ("Your session can not be verified")
if (isset($GLOBALS['egw']->session)) $GLOBALS['egw']->session->commit_session();

View File

@ -15,6 +15,14 @@
*/
class egw_json_request
{
private static $_hadJSONRequest = false;
public static function isJSONRequest()
{
return self::$_hadJSONRequest;
}
/**
* Parses the raw input data supplied with the input_data parameter and calls the menuaction
* passing all parameters supplied in the request to it.
@ -24,6 +32,9 @@ class egw_json_request
*/
public function parseRequest($menuaction, $input_data)
{
// Remember that we currently are in a JSON request - e.g. used in the redirect code
self::$_hadJSONRequest = true;
if (empty($input_data))
{
$this->handleRequest($menuaction, array());
@ -179,6 +190,11 @@ class egw_json_response
return self::$response;
}
public static function isJSONResponse()
{
return isset(self::$response);
}
/**
* Private function used to send the HTTP header of the JSON response
*/

View File

@ -226,12 +226,21 @@ function egw_json_request(_menuaction, _parameters, _context)
this.onLoadFinish = null;
this.loadedJSFiles = {};
this.handleResponseDone = false;
this.app = null;
if (window.egw_alertHandler)
{
this.alertHandler = window.egw_alertHandler;
}
}
/**
* Sets the "application" object which is passed to egw_appWindowOpen when a redirect is done
*/
egw_json_request.prototype.setAppObject = function(_app)
{
this.app = _app;
}
egw_json_request.prototype._assembleAjaxUrl = function(_menuaction)
{
// Retrieve the webserver url
@ -423,7 +432,7 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
}
else
{
window.location.href = res.data.url;
egw_appWindowOpen(this.app, res.data.url);
}
hasResponse = true;