/    Sign up×
Community /Pin to ProfileBookmark

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;
}
}
}
}

}
[/code]

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.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Dec 10.2006 — xho.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");


Eric
×

Success!

Help @gregson09 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...