Sign in to follow this  

[web] IE - Cache Problem? JavaScript

This topic is 3785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm kinda new to javascript and I got a script to work nicely. There is only one problem left in IE. It seems as if caching is responsible, but that would be weird I guess. I use onKeyup for a textfield to execute a script. However the script doesn't always get executed. Let's say I enter Admin in a membername field. Until Ad the status is "Membername is too short". From Adm on it jumps to "Membername is valid". For Admin it tells: "Membername is already taken". So far so good ... but if I delete characters then ... the script isn't called any more. Just as if IE knows "Admi" and thinks it doesn't have to call the script again. Might that be the reason? Do I have to disable caching of something? Is that even possible? Or any other ideas of where I can look if caching can not possibly play a role ...

Share this post


Link to post
Share on other sites
Could you post your JS code? I recall IE having issues with onkeypress for me, but not for onkeyup. I have made an autotab jQuery plugin and had to make an IE conditional, but that was in regards to onkeypress, not onkeyup.

Share this post


Link to post
Share on other sites
Thanks for your reply. Guess I should start a onkeyup research.
Thought something like that must be a general thing. But that might be something.

Sure ... this is the code. Html and javascript:

This is the HTML part ...


<ul class="setting floatleft">
<li>
<p class="floatleft"><label>Member Name:</label></p>
<p class="floatright"><input type="text" id="membername" name="membername" onKeyup="update_infos('./');" /></p>

<br class="newline" />
</li>
<li>
<p class="floatleft"><label>Password:</label></p>
<p class="floatright"><input type="password" id="password" name="password" onKeyup="update_infos('./');" /></p>
<br class="newline" />
</li>
<li>

<p class="floatleft"><label>Confirm Password:</label></p>
<p class="floatright"><input type="password" id="confirm_password" name="confirm_password" onKeyup="update_infos('./');" /></p>
<br class="newline" />
</li>
<li>
<p class="floatleft"><label>e-Mail address:</label></p>
<p class="floatright"><input type="text" id="mailaddress" name="mailaddress" onKeyup="update_infos('./');" /></p>
<br class="newline" />

</li>
<li>
<p class="floatleft"><label>Confirm e-Mail address:</label></p>
<p class="floatright"><input type="text" id="confirm_mailaddress" name="confirm_mailaddress" onKeyup="update_infos('./');" /></p>
<br class="newline" />
</li>
</ul>



And this is the javascript file ...


var req = null;

function get_request() {
req = null;
try {
req = new XMLHttpRequest();
} catch (ms) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (nonms) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
req = null;
}
}
}
}

function get_captcha(Rootpath) {
captcha_req = null;

try {
captcha_req = new XMLHttpRequest();
} catch (ms) {
try {
captcha_req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (nonms) {
try {
captcha_req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
captcha_req = null;
}
}
}

if (null==captcha_req) {
alert('JavaScript Error. Request can not be created!');
} else {
captcha_req.open("GET", Rootpath + "ajax/captcha.php", true);

captcha_req.onreadystatechange = function() {
switch(captcha_req.readyState) {
case 4:
if (captcha_req.status!=200) {
alert("Error: "+captcha_req.status);
} else {
document.getElementById('viewcaptcha').innerHTML =
'<strong>' + captcha_req.responseText + '</strong>';
}
break;
default:
return false;
break;
}
};

captcha_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
captcha_req.send(null);
}
}

function get_passwordconfirmStatus() {

var password = document.getElementById('password').value;
var passwordconfirm = document.getElementById('confirm_password').value;

if ('' == password) {
document.getElementById('passwordconfirm_info').innerHTML =
'<strong class="orange">&bull; ...</strong>';
} else {
if ('' == passwordconfirm) {
document.getElementById('passwordconfirm_info').innerHTML =
'<strong class="orange">&bull; Please match the password!</strong>';
} else {
if (password == passwordconfirm) {
document.getElementById('passwordconfirm_info').innerHTML =
'<strong class="green">&bull; Password matched properly!</strong>';
} else {
document.getElementById('passwordconfirm_info').innerHTML =
'<strong class="orange">&bull; Password and confirmation do not match!</strong>';
}
}
}
}

function get_mailaddressconfirmStatus() {

var mailaddress = document.getElementById('mailaddress').value;
var mailaddressconfirm = document.getElementById('confirm_mailaddress').value;

if ('' == mailaddress) {
document.getElementById('mailaddressconfirm_info').innerHTML =
'<strong class="orange">&bull; ...</strong>';
} else {
if ('' == mailaddressconfirm) {
document.getElementById('mailaddressconfirm_info').innerHTML =
'<strong class="orange">&bull; Please match the e-Mail address!</strong>';
} else {
if (mailaddress == mailaddressconfirm) {
document.getElementById('mailaddressconfirm_info').innerHTML =
'<strong class="green">&bull; e-Mail address matched properly!</strong>';
} else {
document.getElementById('mailaddressconfirm_info').innerHTML =
'<strong class="orange">&bull; e-Mail address and confirmation do not match!</strong>';
}
}
}
}

function set_membernameinfo() {
if ('unknown' == document.getElementById('membername_status').value) {
document.getElementById('membername_info').innerHTML =
'<strong class="orange">&bull; The membername status is unknown!</strong>';
} else if ('empty' == document.getElementById('membername_status').value) {
document.getElementById('membername_info').innerHTML =
'<strong class="orange">&bull; Please enter a membername!</strong>';
} else if ('short' == document.getElementById('membername_status').value) {
document.getElementById('membername_info').innerHTML =
'<strong class="orange">&bull; The name is too short!</strong>';
} else if ('taken' == document.getElementById('membername_status').value) {
document.getElementById('membername_info').innerHTML =
'<strong class="orange">&bull; This membername is already taken!</strong>';
} else if ('valid' == document.getElementById('membername_status').value) {
document.getElementById('membername_info').innerHTML =
'<strong class="green">&bull; The membername is valid!</strong>';
} else if ('invalid' == document.getElementById('membername_status').value) {
document.getElementById('membername_info').innerHTML =
'<strong class="orange">&bull; The membername is not valid!</strong>';
} else {
document.getElementById('membername_info').innerHTML =
'<strong class="orange">&bull; Unexpected status: ' + status + '</strong>';
}
}

function set_passwordinfo() {
if ('unknown' == document.getElementById('password_status').value) {
document.getElementById('password_info').innerHTML =
'<strong class="orange">&bull; The password status is unknown!</strong>';
} else if ('empty' == document.getElementById('password_status').value) {
document.getElementById('password_info').innerHTML =
'<strong class="orange">&bull; Please enter a password!</strong>';
} else if ('short' == document.getElementById('password_status').value) {
document.getElementById('password_info').innerHTML =
'<strong class="orange">&bull; The password is too short!</strong>';
} else if ('unsafe' == document.getElementById('password_status').value) {
document.getElementById('password_info').innerHTML =
'<strong class="yellow">&bull; This password is valid but unsafe!</strong>';
} else if ('valid' == document.getElementById('password_status').value) {
document.getElementById('password_info').innerHTML =
'<strong class="green">&bull; The password is valid and safe!</strong>';
} else if ('invalid' == document.getElementById('password_status').value) {
document.getElementById('password_info').innerHTML =
'<strong class="orange">&bull; The password is not valid!</strong>';
} else {
document.getElementById('password_info').innerHTML =
'<strong class="orange">&bull; Unexpected status: ' + status + '</strong>';
}
}

function set_mailaddressinfo() {
if ('unknown' == document.getElementById('mailaddress_status').value) {
document.getElementById('mailaddress_info').innerHTML =
'<strong class="orange">&bull; The e-mail address status is unknown!</strong>';
} else if ('empty' == document.getElementById('mailaddress_status').value) {
document.getElementById('mailaddress_info').innerHTML =
'<strong class="orange">&bull; Please enter a valid e-mail address!</strong>';
} else if ('valid' == document.getElementById('mailaddress_status').value) {
document.getElementById('mailaddress_info').innerHTML =
'<strong class="green">&bull; The e-mail address appears to be valid!</strong>';
} else if ('invalid' == document.getElementById('mailaddress_status').value) {
document.getElementById('mailaddress_info').innerHTML =
'<strong class="orange">&bull; The e-mail address is not valid!</strong>';
} else {
document.getElementById('mailaddress_info').innerHTML =
'<strong class="orange">&bull; Unexpected status: ' + status + '</strong>';
}
}

function update_infos(Rootpath) {

get_request();

if (null==req) {
alert('JavaScript Error. Request can not be created!');
} else {
url = Rootpath + "ajax/getinfos.php?name=" + document.getElementById('membername').value + "&pass=" + document.getElementById('password').value + "&address=" + document.getElementById('mailaddress').value;
req.open("GET", url, true);

req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(null);

req.onreadystatechange = function() {
switch(req.readyState) {
case 4:
if (req.status!=200) {
alert("Error: "+req.status);
} else {
xml = req.responseXML;
name = xml.getElementsByTagName("membername")[0].firstChild.nodeValue;
pass = xml.getElementsByTagName("password")[0].firstChild.nodeValue;
mail = xml.getElementsByTagName("mailaddress")[0].firstChild.nodeValue;

// alert('name=' + name + ' pass=' + pass + ' mail=' + mail);

document.getElementById('membername_status').value = name;
set_membernameinfo();
document.getElementById('password_status').value = pass;
set_passwordinfo();
document.getElementById('mailaddress_status').value = mail;
set_mailaddressinfo();
}
break;
default:
return false;
break;
}
};
}

get_passwordconfirmStatus();
get_mailaddressconfirmStatus();
}

Share this post


Link to post
Share on other sites
From what I can see, the JS has either been modified by the forums, or you're simply missing single quotes in multiple spots.

Before:
if (' == password) {

After:
if ('' == password) {

There are multiple instances of this. If var req = null; is line one, then the single quotes are on lines 68, 72, 92, and 96. If your original is ok in that regard, then could you provide a link for me to see this in action since you are using AJAX?

Share this post


Link to post
Share on other sites
Sure ... stupid me. It's not like there is only the local version.
I think you should be able to access the js file. Didn't notice that the script got messed up (I made some minor changes, but the behauviour didn't change):

Ajax.js - Source

And this is the site where the script is called:

Registration

Btw ... there is almost no functionality. Its pretty much only layout so far ...

Share this post


Link to post
Share on other sites
Hard to see what the problem is to be honest. The only odd thing I'm seeing is in your HTML. You've specified XHTML, and as such, all attributes need to be lowercase. You have onKeyup, which should read onkeyup.

Can't really see anything else :\

Share this post


Link to post
Share on other sites
That's fine. Thanks for taking the time. :)

Now I'm just wondering if ...

- ... it is just me and my IE Version ...
(I have the stong feeling that the IE on that PC is stuck in a buggy Beta version)

- ... or if you (or anybody else) gets the same weird behavour in IE.


Guess there is probably a workaround. And if there is I'll find it.

Share this post


Link to post
Share on other sites
Weird ... it was the server side caching. Just had to change the header of the XML file that the client requests.
Now I wonder why it did work in Firefox. Maybe the request is different there and generally forbids cached responses?

Share this post


Link to post
Share on other sites

This topic is 3785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this