Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 10th, 2006, 03:13 PM
Registered User
 
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default AJAX and Browser Caches

Hello everyone, I hope you can help!

I have a form with a number of checkboxes. If a checkbox is selected, some of the others may need to be disabled. So I use onClick to call a JavaScript function which uses XmlHttpObject to query from a database if any checkboxes should be disabled as a result (using PHP/MySQL) - I send back an array of integers using JSON (lets call it array X). The JavaScript function then checks all the checkboxes in the form - if the value of any checkbox appears in X, that checkbox is disabled.

This works perfectly using the JavaScript code below when caching is turned ON in IE (options 2,3 or 4 under cache settings). The necessary checkboxes are all disabled instantly. The problem is when the cache is turned OFF (option 1)

Code:
function isInArray(elem,arr) {
/* Returns true if elem is present in the given array, arr */
  var arrLength = arr.length;
  for ( var i=0; i<arrLength; i++ ) {
    if ( arr[i] == elem ) { return true; }
  }
  return false;
}

function handleClashes(inputCheckbox) {
/* Returns a (possible empty) array of all the shifts which clash with the given shift */

var xho=GetXmlHttpObject();
if (!xho) {
  alert ("This browser does not support the technology required to use this website.");
  return false;
}
url = "phplib.php?function=getClashesArray&selectedID=" + inputCheckbox.value;
var clashingShiftIDs = new Array();
xho.onreadystatechange = function() {
  if ( xho.readyState==4) {
    clashingShiftIDs = eval("(" + xho.responseText + ")");
  } 
}
xho.open("GET",url,true);
xho.send(null);       

numCheckboxes = document.bookin.availshifts.length;
if (inputCheckbox.checked == true) {
/* Cycle through all enabled checkboxes, disable those with a value which appears in overlapShifts */        
  for ( var i=0; i<numCheckboxes; i++ ) {
    iCheckbox = document.bookin.availshifts[i];
    if ( iCheckbox.disabled == false && iCheckbox.value != inputCheckbox.value ) {
      // alert ( "If caching is off, this is needed" );
      if ( isInArray(iCheckbox.value, clashingShiftIDs) ) {
        iCheckbox.disabled = true;
      }
    }
  }
}

}
The problem? If, in Internet Explorer, the browser cache is turned OFF (ie. set to check for new versions of a page at every visit - option 1 under cache settings), then this code only works if I uncomment the alert in the code above. The alerts come up and the necessary checkboxes disabled one by one.

I'll be honest, Im not even sure where to start looking for a solution to this problem! Any suggestions?

Thanks very much for your help!

Keith

PS. Im not sure how to change browser cache settings in Firefox, but the default behaviour is as described in the problem above - it needs the alert to work.
 
Old December 11th, 2006, 06:44 AM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rsadalarasu
Default

Try changing your url like this..

url = "phplib.php?function=getClashesArray&selectedI D=" + inputCheckbox.value+"&date="+new Date()

(or)
try this

response.setHeader("Cache-Control", "no-cache");

I think this will solve your problem.

Regards
RSA





Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser Caching with AJAX atcs2152 Ajax 15 February 1st, 2007 10:26 PM
Recommend an AJAX IDE - JoyiStar AJAX WebShop. kingstar Ajax 4 December 15th, 2006 05:12 AM
New Ajax article: Creating an Ajax Search W jminatel BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 May 11th, 2006 03:45 PM
new Ajax article: Creating an Ajax Search Widget jminatel Ajax 0 May 11th, 2006 02:50 PM
New Ajax Article: Ajax Submission Throttling jminatel Ajax 0 April 11th, 2006 08:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.