simple XMLHttpRequest logging function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Steviebone
    New Member
    • Sep 2013
    • 6

    simple XMLHttpRequest logging function

    I am using XMLHttpRequest as a simple one way ajax logging function. No server response is needed. The request does not cross domains.

    This code works as expected in IE and in Firefox

    Code:
    var client2 = new XMLHttpRequest();
    client2.open("GET", "program?url=c",true);
    client2.send();
    alert('sent');
    return true;
    however, as soon as I remove the alert() it fails in Firefox

    Code:
    var client2 = new XMLHttpRequest();
    client2.open("GET", "program?url=c",true);
    client2.send();
    return true;
    the server never receives the call...

    When I step thru this in firebug, I can remove the alert line and once I step thru to the return line the function works as expected. But as soon as I eliminate the debugger (no break) it ceases to work again? very strange. no errors thrown.

    I have tested this on crossbrower testing site live and determined that it is not a problem localized to my machine. The code works as expected in IE but requires the alert() to be fired in Firefox.

    I tried this code with jquery.ajax with same results... in firefox, the request only works if the alert() line is present. I removed firebug, no luck. Tried corssbrowser testing again, same results...

    I'm stumped... :(
    Last edited by Dormilich; Sep 10 '13, 08:35 PM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    not really a solution, but if you don’t expect a response, why not making it an sync call?

    PS. I would at least send a 204 No Content Response.

    PPS. how about a HEAD request instead of a GET? that doesn’t expect response content to begin with.

    Comment

    • Steviebone
      New Member
      • Sep 2013
      • 6

      #3
      well i do give a response and the response is returned properly according to firebug... i just don't use it for anything, it's irrelevant..

      the call needs to async so the rest of the page does not hang or pause loading

      I can't understand why adding the alert() solves the problem... it's very weird. Same problem occurs whether calling xmhtlhttpreques t directly or using the jquery wrapper... if I step thru the code in firebug, I can remove the alert() call and when I get to the return true the call has been fired successfully... however, as soon as a kill the breakpoints the problem returns...

      thank you for your input!

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        does it change, if you define a readystatechang e handler?

        Comment

        • Steviebone
          New Member
          • Sep 2013
          • 6

          #5
          fascinating... in every debugger using step breakpoints the function works as expected until the breakpoints are removed, then the problem returns..

          and yes... I defined a handler... if the handler invokes an alert it works, no alerts, no go...

          BUT! your suggestion got me thinking and I figured I should try it just to see..

          setting the async to false fixes the problem... but I don't want a synchronous event... so what could the culprit be?

          Comment

          • Steviebone
            New Member
            • Sep 2013
            • 6

            #6
            update:

            Changing the async flag to false solves the problem apparently. (There were some random issues so I can't say that 100% definitvely yet).

            However, it is confusing to me that the code runs fine in IE. Since it is a simple message to the server I dont' see how this should matter. Note that it is not the response timing that is an issue because the server never receives the request (and so therefore no reply). As near as I can tell, the send() fails for some reason with no exception or error thrown that I can find.

            The logs to the server are busy but I have done several tests that indicate that the request is never received at all in these instances.

            I experimented with adding a readystatechang e hook even tho a reply is not needed but saw no difference.

            If the problem persists I will try and craft a separate page for testing that I am able to share. Thank you for taking the time to respond. :)

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              just a thought from google, do you call the page via file:// or via http:// ?

              Comment

              Working...