[SOLVED] XmlHttpRequest not working properly

This is a discussion on "[SOLVED] XmlHttpRequest not working properly" within the JavaScript Forum section. This forum, and the thread "[SOLVED] XmlHttpRequest not working properly are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jan 30th, 2008, 14:04
Junior Member
Join Date: Oct 2007
Location: UK
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
[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: Select all
<!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>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jan 31st, 2008, 05:11
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: XmlHttpRequest not working properly

What is Wii by the way..
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jan 31st, 2008, 05:43
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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: Select all
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jan 31st, 2008, 20:33
Junior Member
Join Date: Oct 2007
Location: UK
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
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.
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

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 Forum 1 Jan 24th, 2008 04:24
Problems with XmlHttpRequest Object: readystate won't go past 1 hype JavaScript Forum 1 Jan 13th, 2008 14:18
[SOLVED] Webpage not displaying properly in Firefox Johnathan Web Page Design 25 Jan 5th, 2008 01:34
xmlhttprequest, firefox hangs on 3rd call simonB2007 JavaScript Forum 0 Jun 12th, 2007 15:26
background-repeat: repeat y not working properly AdRock Web Page Design 12 Feb 25th, 2007 22:17


All times are GMT. The time now is 21:18.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42