Weird JS thing
-
I think it's fair to post this here because I'm not asking a question, just airing for your amusement, even if it's code related. I've just been doing some work on a web (well, intranet) system, and we use AJAX to populate a dropdown based on other selections on the form. When a first option is selected, we request a list of days that it is valid on for the user to select one, and the AJAX response is something like
Y
1|Monday
3|Wednesday
4|Thursday... where the first line is a flag to set a checkbox. My AJAX response code included something similar to the following:
var lines = link.responseText.split('\n');
// ... some stuff for dropdown
var show = 'Y' == lines[0][0]; // (1)
checkboxDiv.style.display = show ? '' : 'none';This worked fine, cross browser compatibility was no problem, even IE could cope with it. We deployed the system ... and suddenly we were getting weird behaviour with the checkbox not appearing. After a bit of digging, I tracked it down to line (1). On the live system, I had to use
var show = 89 == lines[0].charCodeAt(0); // (1a)
In the local system, and in all other browsers, even if I set the AJAX target to the live system's URL, it worked fine both ways. I never did work out what the difference could be. Computers, huh. Can't trust them. :~
-
I think it's fair to post this here because I'm not asking a question, just airing for your amusement, even if it's code related. I've just been doing some work on a web (well, intranet) system, and we use AJAX to populate a dropdown based on other selections on the form. When a first option is selected, we request a list of days that it is valid on for the user to select one, and the AJAX response is something like
Y
1|Monday
3|Wednesday
4|Thursday... where the first line is a flag to set a checkbox. My AJAX response code included something similar to the following:
var lines = link.responseText.split('\n');
// ... some stuff for dropdown
var show = 'Y' == lines[0][0]; // (1)
checkboxDiv.style.display = show ? '' : 'none';This worked fine, cross browser compatibility was no problem, even IE could cope with it. We deployed the system ... and suddenly we were getting weird behaviour with the checkbox not appearing. After a bit of digging, I tracked it down to line (1). On the live system, I had to use
var show = 89 == lines[0].charCodeAt(0); // (1a)
In the local system, and in all other browsers, even if I set the AJAX target to the live system's URL, it worked fine both ways. I never did work out what the difference could be. Computers, huh. Can't trust them. :~
-
Could it be that lines[0][0] returned a longer string on the target system (carriage return ?) In this case, the code (1) would not work anymore, whereas code (1a) would, though being apparently identical.
Something like that would make sense except that the same browser (I think it was IE8) would act differently depending on whether the host URL (not even the AJAX lookup one) was localhost/... or deployed_domain.example.com/... . Edi: the same browser on the same machine, i.e. you could set up two tabs in the same browser instance pointing at the two URLs and it would work for one and not the other.
-
Something like that would make sense except that the same browser (I think it was IE8) would act differently depending on whether the host URL (not even the AJAX lookup one) was localhost/... or deployed_domain.example.com/... . Edi: the same browser on the same machine, i.e. you could set up two tabs in the same browser instance pointing at the two URLs and it would work for one and not the other.
-
Something like that would make sense except that the same browser (I think it was IE8) would act differently depending on whether the host URL (not even the AJAX lookup one) was localhost/... or deployed_domain.example.com/... . Edi: the same browser on the same machine, i.e. you could set up two tabs in the same browser instance pointing at the two URLs and it would work for one and not the other.
What were the different servers? Is there a header that is forcing the browser into a different mode?
Curvature of the Mind now with 3D
-
What were the different servers? Is there a header that is forcing the browser into a different mode?
Curvature of the Mind now with 3D
-
Local was a Visual Studio local ASP web server. Deployment was some sort of IIS. So I guess it must be something like this. I don't care enough to find out now, since my involvement with this application is over anyway :p
Yeah, IE can do some weird crap based on URL. For intranet zone sites I think it defaults to IE6 compatibility.
Curvature of the Mind now with 3D