Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old January 30th, 2008, 10:04 AM   #1
New Member
 

Join Date: Oct 2007
Location: UK
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 djeyewater is on a distinguished road
[SOLVED] XmlHttpRequest not working properly

I'm trying to learn javascript at the moment, but am having a problem with XmlHttpRequest.

Hopefully someone can help me out with this one, the following code works on my PC using Opera/9.24 (Windows NT 6.0; U; en) (and other browsers), but not on the Wii.

On the Wii, it will alert "file found" (see line57 of the code), so I guess it must create the object okay, but it does not alert the responseText on the following line. Nor does it alert an error message. I did some googling, but couldn't see anything about the Wii not supporting responseText and I'm pretty sure responseText is used in google maps which work on the Wii.

So, it's probably something wrong with my code. If anyone can help with this it would be greatly appreciated!

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
    
    
function createXmlHttpRequest()
{
    if (window.XMLHttpRequest)
    {
        var oHttp = new XMLHttpRequest();
        return oHttp;
    }
    
    //IE5 & 6
    else if (window.ActiveXObject)    
    {
        try
        {
            var oHttp = new ActiveXObject("MSXML2.XmlHttp.6.0");
            return oHttp;
        }
        catch(error)
        {
            try
            {
                var oHttp = new ActiveXObject("MSXML2.XmlHttp.3.0");
                return oHttp;
            }
            catch(error)
            {return null;}
        }
    }
}


    </script>
    </head>
    
    <body>
    <script type="text/javascript">
    var myAJAX = createXmlHttpRequest();
    myAJAX.open("GET", "text.txt", true);
    myAJAX.onreadystatechange = readyStateChange;
    myAJAX.send(null);
    
    function readyStateChange()
    {
        if(myAJAX.readyState == 4)
        {
            //Object fully loaded & requested data received
            if(myAJAX.status == 200)
            {
                try
                {alert("file found"); 
                alert(myAJAX.responseText);}
                catch(error)
                {alert(error);}
            }
            else if (myAJAX.status == 404)
            {alert("file not found");}
            else
            {alert("an error occurred, Error code="+myAJAX.status);}
        }
    }


</script>
</body>
</html>
djeyewater is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 31st, 2008, 01:11 AM   #2
Most Reputable Member
 

Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Altering Power: 0 Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough
Re: XmlHttpRequest not working properly

What is Wii by the way..
Monie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 31st, 2008, 01:43 AM   #3
Highly Reputable Member
 

Join Date: Apr 2007
Location: Willich, Germany
Age: 22
Posts: 592
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough
Re: XmlHttpRequest not working properly

Quote:
Originally Posted by Monie View Post
What is Wii by the way..
Gaming console from Nintendo. Kind of a weird platform to be testing on

But, back on topic; I can't see any errors in your code, but when I do AJAX I use slightly different objects:
Code:
try {
    return new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
    try {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
}
If that doesn't help, try debugging a bit more in detail using alerts to see exactly how far the request goes.
c010depunkk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 31st, 2008, 04:33 PM   #4
New Member
 

Join Date: Oct 2007
Location: UK
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 djeyewater is on a distinguished road
Re: XmlHttpRequest not working properly

Hi

Thanks for your reply. I had not heard of using those program ids before, but after doing a bit of googling (and reading http://forums.asp.net/t/1000060.aspx?PageIndex=2) it seems they just use version 3 or lower. Since version 3 is installed with IE6, I would've thought it would be better to just specify v3 or v6. It shouldn't make any difference on the wii anyway since that uses Opera.

After adding alerts in like you suggested, I found that only the first alert worked on the wii, so removing all the alerts except the one with responseText made it work. But I tried another page with a script that just has a couple of alerts (and doesn't create an XmlHttpRequestObject) and on that page both alerts worked properly, so it's not that the wii can only display one alert per page.

Also, another page very similar to the one I was having trouble with, if I tried to write the responseText to the body and also to a new window it wouldn't work. If I comment out the new window so it just writes to the page it works.

So I guess the problem is solved (for this example anyway), although it would be nice to know why it originally didn't work and if it could be made to work in that way.
djeyewater is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
confirm dialog not working properly in IE... thenamenoonehastaken JavaScript 1 January 24th, 2008 12:24 AM
Problems with XmlHttpRequest Object: readystate won't go past 1 hype JavaScript 1 January 13th, 2008 10:18 AM
[SOLVED] Webpage not displaying properly in Firefox Johnathan HTML, XHTML and CSS 25 January 4th, 2008 09:34 PM
xmlhttprequest, firefox hangs on 3rd call simonB2007 JavaScript 0 June 12th, 2007 11:26 AM
background-repeat: repeat y not working properly AdRock HTML, XHTML and CSS 12 February 25th, 2007 06:17 PM


Search Engine Optimization by vBSEO 3.2.0 RC8