SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Errors sending request in IE7

    I'm using xHttpRequest from www.cross-browser.com to do client side includes of JavaScript, CSS, and HTML. It works fine under Firefox (2) and Opera (9.25) but in Internet Explorer (7.0.5730.11), I get error popups on *some* GET requests. The first GET produces

    A Runtime Error has occurred.
    Do you wish to Debug?

    Line 35034042
    Error: Object expected

    My second GET works fine. My third produces:

    A Runtime Error has occurred.
    Do you wish to Debug?

    Line 35034042
    Error: Object doesn't support this property or method

    My fourth GET works fine.

    I have the MS script debugger installed but since I don't have 35 million lines in my script, clicking Yes to debug doesn't have useful results.

    I've narrowed this down to the line which says:

    _r.send(d);

    The _r object was created with:

    try { _r = new XMLHttpRequest(); }
    catch (e) { try { _r = new ActiveXObject('Msxml2.XMLHTTP'); }
    catch (e) { try { _r = new ActiveXObject('Microsoft.XMLHTTP'); }
    catch (e) { _r = null; _i.error = e; }}}
    if (!_r) { _i.status |= _i.NOXMLOBJ; }

    The only thing different in the four calls to xHttpRequest.send() is the name of the file I'm retrieving and one field in the user data object passed to the response handler.

    I've Googled every combination I can think of and haven't found any definite, relevant answers.

    Any thoughts on what is wrong or how to narrow it down further?

    Thanks!

    Chris

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you by chance assigning a new xhr object to the same (global) variable, possibly while another request is being executed? That should obviously be avoided.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks, no.

    The _r in my previous post is a object member and I create a new object for each request and assign it to a local variable declared with var.

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://developer.mozilla.org/en/docs...etting_Started
    see note 2

    If that's no good, post a bit more code please.

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the link but I've got 14k lines of JS that work in Opera and Firefox and blow up half the time in IE.

    I'm starting to believe that the problem isn't with the send() but with the handling of the response and that happens so fast I was being misled. When I get the text of the file back, I do the following:

    Code:
    function processIncludeData(id, text) {
        var e = document.getElementById(id);
        // The leading <br> is needed to fix an IE7 bug.
        e.innerHTML = '<br>'+text;
        
        var h = document.getElementsByTagName('head')[0];
    
        var links = e.getElementsByTagName('link');
        for (var i = 0; i < links.length; ++i) {
            var l = links[i];
            xSmartLoadStyle(l.href);
        }
    
        var scripts = e.getElementsByTagName('script');
        for (var i = 0; i < scripts.length; ++i) {
            var s = scripts[i];
            if (s.innerHTML) {
    	    var x = document.createElement('script');
                // IE requires us to set .text, other browsers allow .innerHTML
    	    x.text = s.innerHTML;
                h.appendChild(x);
                h.removeChild(x);
            }
            if (s.src) {
                xSmartLoadScript(s.src);
            }
        }
    };
    I recently got the Microsoft Script Editor to work for me and it complains about the
    Code:
    h.appendChild()
    line. Since I already have a comment there that IE is difficult, I wonder if I haven't quite got it to work. In fact, I've verified that the two files that work do NOT have <script> tags in them and the two that fail do. So, is there a more reliable way of injecting JavaScript into a document at runtime?

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried calling processIncludeData directly, ie without ajax?
    Code:
    processIncludeData("someID", "<html><head><script>alert(1);</script><script>alert(2);</script></head><body>test</body></html>");

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jimfraser View Post
    Have you tried calling processIncludeData directly, ie without ajax?
    No. That's an interesting idea. Right now, I'm trying to move all my code from between <script></script> to .js files includes via the 'src' attributes. If that works, I'm done.

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    send() wasn't the problem

    IE lied to me about the location of the problem. I put an alert() after every line and it blew up when send() executed but only because the calback which handled the response blew up. I moved all my JavaScript from inside <script> tags to files referenced by src attributes and it works now in IE, Opera, and FF. I'm curious why I can't include literal source in IE but too busy to find out now. Thanks.


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
  •