Welcome to WebmasterWorld Guest from 54.161.100.24

Forum Moderators: open

Message Too Old, No Replies

XML HttpRequest Trouble

Won't run on XP SP2

     
12:40 am on May 5, 2005 (gmt 0)

New User

10+ Year Member

joined:May 5, 2005
posts:3
votes: 0


I am having issues running the following script on Windows XP SP2 and the latest version of Internet Explorer. It runs fine on Safari, Firefox (Win/Mac), and even MSIE on Win2k. Anyone have any insight on this issue? I might also mention that IE throws no errors.

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.DOMDocument.4.0");
} catch (E) {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
function loadFragmentInToElement(fragment_url, element_id) {
var element = document.getElementById(element_id);
element.innerHTML = '<em>Loading ...</em>';
xmlhttp.open("GET", fragment_url);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
element.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
1:41 am on May 5, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 16, 2004
posts:93
votes: 0


First of all hello to everybody. This is my first time posting here.

You code looks ok to me. I'm using pretty much the same but with some small modifications and it works.

Are you running it in your own computer maybe? If so, IE should give you a warning about ActiveX controls.

Have you checked that the configuration for the IE pop-up blocker is set to advise you? Did you tried to run it on a web server?

Also it would nice if you can post some more info, like the html code.

2:15 am on May 5, 2005 (gmt 0)

New User

10+ Year Member

joined:May 5, 2005
posts:3
votes: 0


Seems to be happening on a variety of machines. I've had users report it not working, and on my test XP SP2 machine it isn't working. Definitely not isolated. It is run off the web server, no ActiveX warnings and pop-up blocker disabled (though that should really be irrelevant in this case). Below is the HTML code:

client.php:


<script src="script.js" type="text/javascript"></script>
<script type="text/javascript">
function URLEncode(text3s)
{
// The Javascript escape and unescape functions do not correspond
// with what browsers actually do...
var SAFECHARS = "0123456789" + // Numeric
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
"abcdefghijklmnopqrstuvwxyz" +
"-_.!~*'()"; // RFC2396 Mark characters
var HEX = "0123456789ABCDEF";
var plaintext = text3s;
var encoded = "";
for (var i = 0; i < plaintext.length; i++ ) {
var ch = plaintext.charAt(i);
if (ch == " ") {
encoded += "+"; // x-www-urlencoded, rather than %20
} else if (SAFECHARS.indexOf(ch)!= -1) {
encoded += ch;
} else {
var charCode = ch.charCodeAt(0);
if (charCode > 255) {
alert( "Unicode Character '"
+ ch
+ "' cannot be encoded using standard URL encoding.\n" +
"(URL encoding only supports 8-bit characters.)\n" +
"A space (+) will be substituted." );
encoded += "+";
} else {
encoded += "%";
encoded += HEX.charAt((charCode >> 4) & 0xF);
encoded += HEX.charAt(charCode & 0xF);
}
}
} // for
return encoded;
};
function send() {
document.getElementById('mon').value='Sending...';
stuff = URLEncode(document.getElementById('text').value);
document.getElementById('text').value='';
document.getElementById('text').focus();
xmlhttp.open('POST',"post.php",false);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send('text=' + stuff);
document.getElementById('mon').value='Done.';
}
function update() {
document.getElementById('mon').value='Retrieving...';
var element = document.getElementById('screen');
xmlhttp.open("GET", 'get.php');
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('mon').value='Done.';
element.value = xmlhttp.responseText;
element.scrollTop = element.scrollHeight;
}
}
xmlhttp.send(null);
}
function TimerGo() {
update();
timerID = setTimeout("TimerGo()", 2000);
}
function start() {
TimerGo();
document.getElementById('text').focus();
timersID = setTimeout("kill()", 120000);
}
function kill() {
window.location="http://-------?TimeExpired";
}
function entsub() {
if (window.event && window.event.keyCode == 13)
send();
else if (window.event && window.event.which == 13)
send();
else
return true;
}
</script>
</head>
<body onload="start()">
<textarea id="screen" rows="30" cols="100" READONLY /></textarea><br>
<input type="text" id="text" size="100" onkeypress="return entsub()" />
<input type="button" value="Click here to send" OnClick="send();" /> <br><br>
<input type="text" id="mon" size="20" />

script.js is in my first post.

4:18 am on May 5, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 14, 2004
posts:1181
votes: 0


I believe SP 2's defaults for ActiveX in IE are more restrictive than prior versions. Have you checked both Tools - Internet Options - Advanced and Security?
10:30 pm on May 5, 2005 (gmt 0)

New User

10+ Year Member

joined:May 5, 2005
posts:3
votes: 0


I've flipped all the checkboxes there, and still no luck. So I suspect it is a security problem - what can I do to fix it? Google Maps and the likes seem to be working fine with it.
8:06 am on May 16, 2005 (gmt 0)

New User

10+ Year Member

joined:Oct 18, 2003
posts:8
votes: 0


With out being able to see the urls (and yes I know the rules around here :)) - here is a shot in the dark

Are you loading the data from an external server? or form [example.com...] when the page is on [example.com...] or [bobo.example.com?...] - (dont know if the last type makes a diff - but worth checking)

Have you tried putting your site in your trusted zone of explorer and then running the page to see if it works? Would be a quick way to find out if its a security issue or not.

Also check to see if toggling the "Open files based on content, not file extension" setting does anything. (This setting likes to hide in the middle of all the misc ones - even when I am looking for it - its a pain to find)

If you are pulling from another domain (which my quess is not - but anyway) - that setting is the first one after in Misc - after ActiveX and Download BS - "Access data sources across domains"

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members