Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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;
}







[/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;
}







[/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.