AJAX and IE - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

AJAX and IE

kiokikioki Posts: 1Member
Hi!I've got huge problem with IE and AJAX.That's my script:
[code]




var xmlHttp;

function go()
{
alert('go()');
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="1.xml";
alert('before stateChanged');
xmlHttp.onreadystatechange=stateChanged;
try{xmlHttp.open("GET",url,true);}catch(e){alert('alert in xmlHttp.open:'+e);}
xmlHttp.send(null);

alert('end');
}

function stateChanged()
{ try{
if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
{
alert('stateChanged() ');
xmlDoc=xmlHttp.responseXML;
document.getElementById("a1").innerHTML=
xmlDoc.getElementsByTagName("part")[0].childNodes[0].nodeValue;
}}catch(e){alert('alert in stateChanged:'+e);}
}

function GetXmlHttpObject()
{
var objXMLHttp=null;
if (window.XMLHttpRequest)
{
alert('window.XMLHttpRequest');
objXMLHttp=new XMLHttpRequest();
alert(objXMLHttp);
}
else if (window.ActiveXObject)
{
alert('window.ActiveXObject');
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return objXMLHttp;
}



go



[/code]
I've got that:
alert in xmlHttp.open:[object Error] (first catch)
I do it that way:
[code]




var xmlHttp;

function go()
{
alert('go()');
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="1.xml";
alert('before stateChanged');
xmlHttp.onreadystatechange=stateChanged;
try{xmlHttp.open("GET",url,true);}catch(e){alert('alert in xmlHttp.open:'+e);}
xmlHttp.send(null);

alert('end');
}

function stateChanged()
{ try{
if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
{
alert('stateChanged() ');
xmlDoc=xmlHttp.responseXML;
document.getElementById("a1").innerHTML=
xmlDoc.getElementsByTagName("part")[0].childNodes[0].nodeValue;
}}catch(e){alert('alert in stateChanged:'+e);}
}

function GetXmlHttpObject()
{
var objXMLHttp=null;
if(navigator.appName == "Microsoft Internet Explorer")
{
alert('IE');
objXMLHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
alert(objXMLHttp);
}
else
{
alert('non IE');
objXMLHttp=new XMLHttpRequest();
alert(objXMLHttp);
}

return objXMLHttp;
}



go



[/code]
And IE shows me that:
alert in stateChanged:[object Error] (second catch)
......
What's so wrong?PLS help me!

p.s. the xml file is:
[code]
<?xml version="1.0" encoding="Windows-1251"?>Introduction!
[/code]
Sign In or Register to comment.