AJAX

Moderators: None (Apply to moderate this forum)
Number of threads: 54
Number of posts: 84

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
AJAX and IE Posted by kioki on 10 Mar 2009 at 2:42 PM
Hi!I've got huge problem with IE and AJAX.That's my script:
<html>
<head>
<title></title>
<script type="text/javascript">
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;
 }
</script>
</head>
<body>
<button onClick="go()">go</button>
<div id="a1"></div>
</body>
</html>

I've got that:
alert in xmlHttp.open:[object Error] (first catch)
I do it that way:
<html>
<head>
<title></title>
<script type="text/javascript">
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;
 }
</script>
</head>
<body>
<button onClick="go()">go</button>
<div id="a1"></div>
</body>
</html>

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:
<?xml version="1.0" encoding="Windows-1251"?><siteData><part>Introduction!</part></siteData>




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.