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
CODE
<!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
CODE
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
CODE
<?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.