Reply
AJAX and Browser Caches
Old 12-10-2006, 03:20 PM AJAX and Browser Caches
Junior Talker

Posts: 4
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.
gregson09 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Reply     « Reply to AJAX and Browser Caches
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12218 seconds with 12 queries