Welcome to Dream.In.Code
Become an Expert!

Join 149,522 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,390 people online right now. Registration is fast and FREE... Join Now!




xmlhttprequest status always 0

 
Reply to this topicStart new topic

xmlhttprequest status always 0

cybrid
24 May, 2007 - 04:59 AM
Post #1

New D.I.C Head
*

Joined: 7 Sep, 2005
Posts: 35


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Xmlhttprequest Status Always 0
24 May, 2007 - 07:17 AM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
try the code located here if this works, then it is a problem with your connection and not your applications.
User is offlineProfile CardPM
+Quote Post

cybrid
RE: Xmlhttprequest Status Always 0
25 May, 2007 - 10:56 AM
Post #3

New D.I.C Head
*

Joined: 7 Sep, 2005
Posts: 35


My Contributions
Hey, thx for the tip, I'll try and tell you. Many thanks.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:33PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month