2 Replies - 2345 Views - Last Post: 25 May 2007 - 11:56 AM

#1 cybrid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 07-September 05

xmlhttprequest status always 0

Posted 24 May 2007 - 05:59 AM

Hi everyone at dream.in.code

I just wanted to ask, I've been trying to setup a simple AJAX script to retrieve a xml file but whenever I run it, status is always 0. Can somebody throw some light at this issue?. I simply installed an Apache 2.2.4 and created a directory called "test" under the "htdocs" directory of Apache. This is the code I'm using:

index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
	<script type="text/javascript" src="ajax.js"></script>
	</head>
	<body onload="doRequest('data.xml')">
		<div id="data">
		</div>
	</body>
</html>



ajax.js
var req;
var ie = false;

function doRequest(url){
	if (window.XMLHttpRequest){
		try{
			req = new XMLHttpRequest();
		}catch (e){
			req = false;
		}
	}else if (window.ActiveXObject){
		ie = true;
		try{
			req = new ActiveXObject ("Msxml2.XMLHTTP");
		}catch (e){
			try{
				req = new ActiveXObject ("Microsoft.XMLHTTP");
			}catch (e){
				req = false;
			}
		}
	}
	if (req){
		req.onreadystatechagne = processReq;
		req.open ("GET", url, true);
		if (ie){
			req.send("");
		}else{
			req.send(null);
		}
	}
}
function processReq (){
	if (req.readyState == 4){
		alert ("Request State is: "+req.readyState);
		if (req.status == 200){
			alert ("Status is: "+req.status);
			document.getElementsById("data").innerHTML = req.responseXML.getElementById("data");
		}else{
			alert ("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}



data.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data>
	<nickname>Cybrid</nickname>
	<email>xabier.burgos@gmail.com</email>
	<name>Xabier</name>
	<surname>Burgos</surname>
	<country>Spain</country>
</data>


Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: xmlhttprequest status always 0

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: xmlhttprequest status always 0

Posted 24 May 2007 - 08:17 AM

try the code located here if this works, then it is a problem with your connection and not your applications.
Was This Post Helpful? 0
  • +
  • -

#3 cybrid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 07-September 05

Re: xmlhttprequest status always 0

Posted 25 May 2007 - 11:56 AM

Hey, thx for the tip, I'll try and tell you. Many thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1