/    Sign up×
Community /Pin to ProfileBookmark

Works great under FF, bad under IE

Hi, i’ve got some problems with my script. It works perfect under Firefox, but does nothing under Internet explorer. What can I do about it?

I use this in de <head>:

[code=php]</form><p><span id=”txtHint”></span></p>
<script>
function showHint()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert (“Browser does not support HTTP Request”)
return
}
var url = “check_time.php”
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open(“GET”,url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState==”complete”)
{
document.getElementById(“txtHint”).innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject(handler)
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject(“Microsoft.XMLHTTP”)
}
return objXMLHttp
}
setInterval(showHint, 1000);

</script>[/code]

and this in the body:

[code=php]<body Onload=showHint()>[/code]

Please help me.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@cobblerJun 28.2007 — You need to check for the versions of objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")

An example is at http://javascript.about.com/library/blajax01.htm
Copy linkTweet thisAlerts:
@pistolpauthorJun 29.2007 — Oké, now I tried this, it still works in FF but has no effects in IE. IE gives a runtime error for this line:
[code=php]document.getElementById("txtHint").innerHTML=xmlHttp.responseText[/code]

My new document is:

[code=php]<script>

if (typeof XMLHttpRequest != 'undefined')
return new XMLHttpRequest();
else if (window.ActiveXObject) {
var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp",
"MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.5.0"];
for (var i = avers.length -1; i >= 0; i--) {
try {
httpObj = new ActiveXObject(avers[i]);
return httpObj;
} catch(e) {}
}
}
throw new Error('XMLHttp (AJAX) not supported');


var ajaxObj = createXMLHttp();

function showHint()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url = "check_time.php"
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject(handler)
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
setInterval(showHint, 1000);

</script>[/code]
×

Success!

Help @pistolp 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.7,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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