SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX Problem Specific to IE

    Hi. I have a script that uses Ajax and works 100% perfectly in both Firefox and Netscape, but it doesn't quite work in IE. Not surprisingly, the IE error message ("Unspecified error") is useless. I'm new to Ajax and would greatly appreciate any help.

    Here's the URL: http://www.netservicesgroup.com/tools.php

    Try typing disgruntledgoat.com in the appropriate text field and make sure the "All" radio button is checked. Then click on "Go". I deliberately selected a domain that has a messed up result for traceroute. What it's supposed to do, what it does in Firefox and Netscape, and the whole reason I'm using Ajax in the first place, is display the result line by line as it becomes available. So you should immediately see the first 8 lines or so of the result underneath where it says "Trace Route:", and then you'll see three asterisks per line every several seconds to a total of 30 lines. In IE, however, nothing appears until the entire result is available (seemingly forever), which defeats the purpose of having used Ajax. It also generates the meaningless Javascript error message.

    Here's the relevant Javascript code, adapted from the Simply Javascript book:

    Code:
    function getHTTPObject()
    {
        var xhr = false;
        if(window.XMLHttpRequest)
        {
            xhr = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            try
            {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e)
                {
                    xhr = false;
                }
            }
        }
        return xhr;
    }
    function grabFile(file,query,addr,router)
    {
        var request = getHTTPObject();
        if (request)
        {
            request.onreadystatechange = function()
            {
                parseResponse(request,query);
            }
            request.open("POST", file, true);
            request.send("query=" + query + "&addr=" + addr + "&router=" + router);
        }
    }
    function parseResponse(request,query)
    {
        if (request.readyState == 3 || request.readyState == 4)
        {
            if (request.status == 200 || request.status == 304)
            {
                var details = document.getElementById(query + "Details");
                details.innerHTML = request.responseText;
            }
            if(request.readyState==4)
            {
                var status=document.getElementById(query + "Status");
                status.innerHTML = "<p><strong>Done!</strong></p>";
            }
        }
    }
    Thanks!

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE works best if you do it in this order:
    request.open...
    request.onreadystatechange = ...
    request.send...

  3. #3
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi. Thanks for the response. I switched the order and, after ensuring that I wasn't stuck with a cached version of the Javascript file, I still get the same result. Still works great in Firefox, doesn't display in IE until entire result is available. Any other thoughts? Thanks!

  4. #4
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone else have any ideas? I'm completely stumped... not to mention very frustrated with IE...

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, right, you're doing the readystate=3 thing.

    Can't do that with the native xmlhttprequest object (see http://msdn.microsoft.com/en-us/libr...61(VS.85).aspx). You might have better luck using the ActiveXObject version and checking the responseStream.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •