By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,404 Members | 2,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,404 IT Pros & Developers. It's quick & easy.

simple XMLHttpRequest logging function

P: 6
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

Expand|Select|Wrap|Line Numbers
  1. var client2 = new XMLHttpRequest();
  2. client2.open("GET", "program?url=c",true);
  3. client2.send();
  4. alert('sent');
  5. return true;
however, as soon as I remove the alert() it fails in Firefox

Expand|Select|Wrap|Line Numbers
  1. var client2 = new XMLHttpRequest();
  2. client2.open("GET", "program?url=c",true);
  3. client2.send();
  4. 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... :(
Sep 10 '13 #1
Share this Question
Share on Google+
6 Replies


Dormilich
Expert Mod 5K+
P: 8,639
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.
Sep 10 '13 #2

P: 6
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 xmhtlhttprequest 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!
Sep 10 '13 #3

Dormilich
Expert Mod 5K+
P: 8,639
does it change, if you define a readystatechange handler?
Sep 10 '13 #4

P: 6
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?
Sep 10 '13 #5

P: 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 readystatechange 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. :)
Sep 11 '13 #6

Dormilich
Expert Mod 5K+
P: 8,639
just a thought from google, do you call the page via file:// or via http:// ?
Sep 11 '13 #7

Post your reply

Sign in to post your reply or Sign up for a free account.