From aed2e27b3f814c90350be72ec95d5d72e9063057 Mon Sep 17 00:00:00 2001 From: ninadsp Date: Thu, 2 Sep 2010 21:47:46 +0530 Subject: [PATCH] A better solution to the caching issues faced. Set jQuery's global Ajax parameter 'cache' to false, and also set the 'Cache-Control' header to 'no-cache' --- js/db_search.js | 8 +++----- js/server_privileges.js | 7 ++----- js/sql.js | 8 +++----- js/tbl_select.js | 8 +++----- libraries/common.lib.php | 1 + server_privileges.php | 5 +++++ 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/js/db_search.js b/js/db_search.js index 94fdf6cf0..3527b62b9 100644 --- a/js/db_search.js +++ b/js/db_search.js @@ -16,13 +16,11 @@ $(document).ready(function() { /** - * Set a parameter for all Ajax queries made on this page. Append a random - * number to tell server that each Ajax request is a new one + * Set a parameter for all Ajax queries made on this page. Don't let the + * web server serve cached pages */ $.ajaxSetup({ - data: {'random': function() { - return Math.random(); - }} + cache: 'false' }); /** diff --git a/js/server_privileges.js b/js/server_privileges.js index dff2c65ba..4ecfea00f 100644 --- a/js/server_privileges.js +++ b/js/server_privileges.js @@ -163,13 +163,10 @@ $(document).ready(function() { /** * Set a parameter for all Ajax queries made on this page. Some queries * are affected by cache settings on the server side, and hence, show stale - * data. Append a random number to tell server that each Ajax request is a - * new one + * data. Don't let the web server serve cached pages */ $.ajaxSetup({ - data: {'random': function() { - return Math.random(); - }} + cache: 'false' }); /** diff --git a/js/sql.js b/js/sql.js index 76e6c4056..ee66044fc 100644 --- a/js/sql.js +++ b/js/sql.js @@ -108,13 +108,11 @@ function appendInlineAnchor(disp_mode) { $(document).ready(function() { /** - * Set a parameter for all Ajax queries made on this page. Append a random - * number to tell server that each Ajax request is a new one + * Set a parameter for all Ajax queries made on this page. Don't let the + * web server serve cached pages */ $.ajaxSetup({ - data: {'random': function() { - return Math.random(); - }} + cache: 'false' }); /** diff --git a/js/tbl_select.js b/js/tbl_select.js index 12072b049..97de18113 100644 --- a/js/tbl_select.js +++ b/js/tbl_select.js @@ -14,13 +14,11 @@ $(document).ready(function() { /** - * Set a parameter for all Ajax queries made on this page. Append a random - * number to tell server that each Ajax request is a new one + * Set a parameter for all Ajax queries made on this page. Don't let the + * web server serve cached pages */ $.ajaxSetup({ - data: {'random': function() { - return Math.random(); - }} + cache: 'false' }); /** diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 2a0563856..7dd39f9b5 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -2937,6 +2937,7 @@ function PMA_ajaxResponse($message, $success = true, $extra_data = array()) // Set the Content-Type header to JSON so that jQuery parses the response correctly if(!isset($GLOBALS['is_header_sent'])) { + header('Cache-Control: no-cache'); header("Content-Type: application/json"); } echo json_encode($response); diff --git a/server_privileges.php b/server_privileges.php index 567a44ce1..710151ef3 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -1731,6 +1731,11 @@ if (empty($_REQUEST['adduser']) && (! isset($checkprivs) || ! strlen($checkprivs // A user was selected -> display the user's properties + // In an Ajax request, prevent cached values from showing + if($GLOBALS['is_ajax_request'] == true) { + header('Cache-Control: no-cache'); + } + echo '

' . "\n" . PMA_getIcon('b_usredit.png') . __('Edit Privileges') . ': '