In Firefox (2.0.0.18) .readyState hung at 3 while .responseText hasthe data but .responseXML is nul.

M

m_p_v_13

In Firefox (2.0.0.18) .readyState hung at 3 where .responseText has
the data but .responseXML is nul.

A school project whiched worked last year is failing now. I've
updated my browser and the LAMP server was probably updated also in
that time.

The problem is that xmlHttp.readyState gets up to 3 and then
no more state changes. It works OK in IE.

I recreated the problem using the sample program found here.

http://www.w3schools.com/php/php_ajax_responsexml.asp

I modified the php to dummy up the data to eliminate the mySQL
and added some alerts.

I suspect the XML parsing is having a problem, however the XML looks
good
when I see it in responsText using firebug.


Please, can anyone shed some light on what is wrong?


Here is the source:

---- hangon3.html ---------------------------
<html>
<head>
<script src="hangon3.js"></script>
</head>
<body>

<form>
Select a User:
<select name="users" onchange="showUser(this.value)">
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>

<h2><span id="firstname"></span>
&nbsp;<span id="lastname"></span></h2>
<span id="job"></span>
<div style="text-align: right">
<span id="age_text"></span>
<span id="age"></span>
<span id="hometown_text"></span>
<span id="hometown"></span>
</div>

</body>
</html>
---------------------------------------------
---- hangon3.php ----------------------------
<?php
header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
//A date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<person>';
echo "<firstname>Michael</firstname>";
echo "<lastname>Vogt</lastname>";
echo "<age>51</age>";
echo "<hometown>Miami</hometown>";
echo "<job>Student</job>";
echo "</person>";
?>
---------------------------------------------
---- hangon3.js -----------------------------
var xmlHttp

function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="hangon3.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
alert("before xmlHttp.send()");
xmlHttp.send(null)
alert("after xmlHttp.send()");
}

function stateChanged()
{
alert( "stateChanged readyState=" + xmlHttp.readyState );
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
alert( "processing XML " + xmlHttp.responseXML );
xmlDoc=xmlHttp.responseXML;
document.getElementById("firstname").innerHTML=
xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue;
document.getElementById("lastname").innerHTML=
xmlDoc.getElementsByTagName("lastname")[0].childNodes[0].nodeValue;
document.getElementById("job").innerHTML=
xmlDoc.getElementsByTagName("job")[0].childNodes[0].nodeValue;
document.getElementById("age_text").innerHTML="Age: ";
document.getElementById("age").innerHTML=
xmlDoc.getElementsByTagName("age")[0].childNodes[0].nodeValue;
document.getElementById("hometown_text").innerHTML="<br/>From: ";
document.getElementById("hometown").innerHTML=
xmlDoc.getElementsByTagName("hometown")[0].childNodes[0].nodeValue;
}
}

function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
---------------------------------------------
 
M

m_p_v_13

Works for me on FF 2.0.0.18.

The script style could be improved, and the HTML would benefit from
validation, but other than that it works as expected.

  - Conrad

Conrad,
Thanks for checking to confirm that it's something peculuar about my
Firefox or LAMP configuration.

Anyone have any ideas on were I should look for the problem?

Since the whole response is in the responseText, I'm guessing it's a
problem parsing the XML. What diagnostics are available for that?
Where do I look for that parts error reporting?

Another hunch I have is than something is misaligned in the
character encoding (I already tried, with no difference, using utf-8
in the xml header).

I'm thinking to try the following:
- use a clean FireFox install,
- use a non xml response
- trace the tcpip

Any other Ideas...?


Thanks for any help
 
M

m_p_v_13

Oh, and I just noticed this:

On 2008-11-27 09:57, m_p_v_13 wrote:
...> //A date in the past

^^^

July 1997
Mo Tu We Th Fr Sa Su
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

That's probably not the reason either, but it should still be fixed :)

- Conrad

Conrad,

Thanks so much for the advice.

I tried on the app from two different clients on different machines
( FF 3, FF 2.0.0.14) and each of these worked (with the server the
same). In the process of uninstalling my FF I noticed the safe mode
(which excludes custimizations, extensions, etc.). I tried that and
it works. So, one of those additons/changes may be involved. I am
using 1/2 dozen debugging add-ons. (web developer,firebug,view
formatted source,live http headers, dom inspector java console). I'll
reinstall and go from here.

Again, thanks so much on this day of thanksgiving... I was starting to
get flustered...It helps to have someone to talk to.

Thanks for pointing out the other code slop. It's all from that
example. A google search on that date gets 62,000 hits. It may be the
original author's "watermark".

I might play around a little to try to isolate the add-on, and if I
find out I'll report back.

Otherwise, the bottom line is:

Some add-on or customization is causing the problem (where readyState
is 1,1,2,3 and never gets to 4, while responseText seems to have
everything but responseXML is nul), since running in firefox safe mode
does not show the problem, with everything else the same.

BTW, I like Ethereal for tcpip tracing, but it may be overkill for
this kind of job.

Michael
 
M

m_p_v_13

I might play around a little to try to isolate the add-on, and if I
find out I'll report back.

I went back to regular (non-safe) mode to try to isolate the add-on
and the problem did not appear.

What the hey...

Then I remembered that prior to trying safe-mode I had cleared all
private data (cache, history, etc )
as part of backing up my profile.

So, it seems, the problem was caused by something in the cache, etc.

I did have some bad xml generated in some iterations of changing the
test program, however, the problem with my original year old program
has cleared up also and that app has not changed.


So, a lesson learned:
Try "clear private data", as a fix to this kind of weird problem.


Regards,
Michael
 
T

Thomas 'PointedEars' Lahn

m_p_v_13 said:
So, it seems, the problem was caused by something in the cache, etc.

I did have some bad xml generated in some iterations of changing the
test program, however, the problem with my original year old program
has cleared up also and that app has not changed.

So, a lesson learned:
Try "clear private data", as a fix to this kind of weird problem.

A more reliable approach to problems of this sort are cache-controlling headers:

<http://www.mnot.net/cache_docs/>

If that does not work for you, you can always append parameters unique over
time (such as a timestamp) to the query part or PATHINFO component of the
request URI. But you should use that only as a last resort as it clutters
up caches, which one wants to avoid.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Conrad said:
Actually, he already did both:

On 2008-11-27 09:57, m_p_v_13 wrote:
| header("Cache-Control: no-cache, must-revalidate");
| //A date in the past
| header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
...

Last-Modified is missing, and the Expires weekday is wrong (as you have
noted before).
| var url="hangon3.php"
| url=url+"?q="+str
| url=url+"&sid="+Math.random()

var url = "hangon3.php"
+ "?q=" + str
+ "&sid=" + Math.random()

would be more efficient and easier to maintain.

However, I have also encountered borken caches before, both in IE
(particularly v6.0) and Firefox (some builds), so it may well have
been only a temporary problem that was fixed with clearing the cache.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
var url = "hangon3.php"
+ "?q=" + str
+ "&sid=" + Math.random()

would be more efficient and easier to maintain.

However, I have also encountered borken caches before, both in IE
(particularly v6.0) and Firefox (some builds), so it may well have
been only a temporary problem that was fixed with clearing the cache.

That said, Math.random() is by its very nature _not_ one of the reliable
means to generate a value that is unique over time which may well have
contributed to the problem. One should use +(new Date()), or, where the
Unary Plus operation is unavailable, (new Date() - 0), Number(new Date()),
or (new Date()).getTime() instead.


PointedEars
 
M

Matthias Watermann

[...]
var url = "hangon3.php"
+ "?q=" + str
+ "&sid=" + Math.random()

would be more efficient and easier to maintain.

Wouldn't

var url = "hangon3.php" +
"?q=" + str +
"&sid=" + Math.random();

"safer" (to avoid the problem of ";" insertion)?


--
Matthias
/"\
\ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
X - AGAINST M$ ATTACHMENTS
/ \
 
T

Thomas 'PointedEars' Lahn

Matthias said:
[...]
var url = "hangon3.php"
+ "?q=" + str
+ "&sid=" + Math.random()

would be more efficient and easier to maintain.

Wouldn't

var url = "hangon3.php" +
"?q=" + str +
"&sid=" + Math.random();

"safer" (to avoid the problem of ";" insertion)?

I don't think so (see ES4F, section 7.9), and I find that also harder to
maintain (looking for operators at the end of the line which may be long,
having the starting string values not aligned with each other).


PointedEars
 
T

Thomas 'PointedEars' Lahn

Matthias said:
[...]
var url = "hangon3.php"
+ "?q=" + str
+ "&sid=" + Math.random()

would be more efficient and easier to maintain.

Wouldn't

var url = "hangon3.php" +
"?q=" + str +
"&sid=" + Math.random();

"safer" (to avoid the problem of ";" insertion)?

I don't think so (see ES3F, section 7.9), and I find that also harder to
maintain (looking for operators at the end of the line which may be long,
having the starting string values not aligned with each other).


PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>, Fri,
That said, Math.random() is by its very nature _not_ one of the reliable
means to generate a value that is unique over time which may well have
contributed to the problem. One should use +(new Date()), or, where the
Unary Plus operation is unavailable, (new Date() - 0), Number(new Date()),
or (new Date()).getTime() instead.

or +new Date() .

But your advice is incorrect.

Firstly, Math.random() generates values from a set of (for well-
implemented browsers) 2^53; assuming true randomness, that's about
10^16, which is a lot, implying only a 1 in 2^16 chance of a repeat on
any given occasion.

Given that most systems nowadays have a broadband connection to a NNTP
clock used at least once a week, and there is presumably a 50% chance of
a given system running fast - then there will be frequent (in comparison
with 10^16) retardations of time. Traditional UNIX does so by slowing
time; but AFAIK Windows does it by setting the clock back. meaning that
some times will be repeated. That will IMHO happen more often than
10^-16 of the time.

Secondly, Math.random() will be controlled not by a true RNG but by a
PRNG. Therefore, at least in a single instance of a browser, it will
only repeat after 2^53 calls, assuming that String(Number) gives a
different string for each different Number. A program using it for the
present purpose needs to avoid making 2^53-1 intervening calls of
Math.random() [but at a million calls a second that would take about
four or five lifetimes].

One can of course use both; but one must concatenate the results rather
than adding them.

<URL:http://www.merlyn.demon.co.uk/js-randm.htm>
 
D

Dr J R Stockton

In comp.lang.javascript message <g7mdnW_ww-42BKzUnZ2dnUVZ_uCdnZ2d@supern
Secondly, Math.random() will be controlled not by a true RNG but by a
PRNG. Therefore, at least in a single instance of a browser, it will
only repeat after 2^53 calls [...]

Do you have any source on that? Never repeating "random" results would
make the PRNG very predictable after a while. (a long while, admittedly)

That is why it is a PRNG rather than a RNG.

Have you read <URL:http://www.merlyn.demon.co.uk/js-randm.htm> as cited
in my previous article? See also <http://en.wikipedia.org/wiki/Random>
and what it links to.

IIRC, some INTEL CPUs do have a true RNG, generating bits from a
"random" physical process. But that's slow and so only useful for
initialisation of PRNGs; and proving lack of bias cannot be easy. I do
not know whether it is often, or ever, used.
 
T

Thomas 'PointedEars' Lahn

Dr said:
[...] Thomas 'PointedEars' Lahn [...] posted:
That said, Math.random() is by its very nature _not_ one of the reliable
means to generate a value that is unique over time which may well have
contributed to the problem. One should use +(new Date()), or, where the
Unary Plus operation is unavailable, (new Date() - 0), Number(new Date()),
or (new Date()).getTime() instead.

or +new Date() .

I have mentioned that. The `new' operation takes precedence, so the outer
parentheses in +(new Date()) are optional.
But your advice is incorrect.

Is that so?
Firstly, Math.random() generates values from a set of (for well-
implemented browsers) 2^53; assuming true randomness, that's about
10^16, which is a lot, implying only a 1 in 2^16 chance of a repeat on
any given occasion.
[...]
Secondly, Math.random() will be controlled not by a true RNG but by a
PRNG. [...]

That's a deductive formal fallacy.

Interesting information you provided aside, it matters _not_ here how the
(pseudo-)random number is being generated and thus how likely repetition
of a value is. What counts is that a value can repeat, and thus random
numbers are unsuitable for generating a value that is unique over time.

I would also like to emphasize that I did not say Math.random() must be the
cause of the problem, but that it *may* have *contributed* to the problem.


PointedEars
 
J

Jorge

Firstly, Math.random() generates values from a set of (for well-
implemented browsers) 2^53; assuming true randomness, that's about
10^16, which is a lot, implying only a 1 in 2^16 chance of a repeat on
any given occasion.

Stockton, I have a question:

Is it possible than you get the same random number if you quit and
reopen the browser ?

IOW, does the PRNG sequence get re-started or re-seeded every time the
browser is opened ?
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>, Sun,
Interesting information you provided aside, it matters _not_ here how the
(pseudo-)random number is being generated and thus how likely repetition
of a value is. What counts is that a value can repeat, and thus random
numbers are unsuitable for generating a value that is unique over time.


In practice there is never any requirement that the value should be
unique over *all* time. The repeat interval of any PRNG likely to be
used for Math.random() is sufficiently long that there will be no repeat
in a single run of a PRNG in a Web page (except perhaps if the page is
running code to call Math.random() at a very high rate). The number of
states is sufficiently large that a repeat across two different runs is
sufficiently unlikely to occur.

However, computer time, being not necessarily monotonic, can repeat with
higher probability.
 
D

Dr J R Stockton

In comp.lang.javascript message <0980febc-4198-4615-b45c-eae91661e585@v1
3g2000yqm.googlegroups.com>, Sun, 30 Nov 2008 14:18:47, Jorge
Stockton, I have a question:

Is it possible than you get the same random number if you quit and
reopen the browser ?

Formally, that is undefined.
IOW, does the PRNG sequence get re-started or re-seeded every time the
browser is opened ?

Undefined.

One might test it by looking at the first value given by Math.random().

It seems highly likely that the PRNG will be initialised from date/time
- in JavaScript, using +new Date should do nicely.

But, with a sensibly-chosen PRNG with 2^N internal states and N at least
32, the chances of an accidental match, in this sort of use, are small.
Less likely than those of you being hit (when well away from any
airstrip) by a crashing plane, but probably more than those of your
being hit by a small meteorite.

NOTE : Google Chrome seems to have a repeat interval of 1073735680 =
0x3FFFE800, but not always.
 
D

Dr J R Stockton

In comp.lang.javascript message <35SdnbH9D55Anq7UnZ2dnUVZ_s7inZ2d@supern
I know how PRNGs work (not the mathematical details, but the general
concept of using generator functions and seeds). I'm still unsure how
the fact that the pseudo-random sequence repeats after a while would
mean that Math.random can never return the same value twice in one
period, that's not an intrinsic property of pseudo random sequences.
Whether numbers can repeat would depend on the length of the sequence
and the precision of the numbers read from it (usually ~2^53 according
to your tests). The type of the PRNG is implementation dependant; some
can have period lengths > 10^30000.

That's nothing. My Delphi program LONGCALC could be programmed (in RPN)
to give a repeat of about 16^99999999, though one would have to
determine what shift-register taps to use for a maximal sequence (I have
a copy of a paper on the subject). However, it would not generate many
such numbers per second. Or maybe per minute. Or hour.



My reasoning does assume that the PRNG is used in a sensible manner.
Obviously one *could* use a 64-bit generator and feed only 4 bits into
Math.random() - that would comply with the specification, but be
ludicrous.

For JavaScript, I think one really needs a true 2^N state generator for
which N is as large as possible but no more than 53. 48 would be
acceptable, if a design for 53 is not known. Every bit of the generator
should appear in the return value considered as an integer.


Tests on Google Chrome suggest that its Math.random() is unreasonable.


PS, just FYI: The "Gofer" function on your page has an undefined
variable reference: Statement on line 4: Undefined variable: X

For X read K - thanks, fixed, uploaded. I wonder how that happened?
 
E

Evertjan.

Dr J R Stockton wrote on 01 dec 2008 in comp.lang.javascript:
That's nothing. My Delphi program LONGCALC could be programmed (in RPN)
to give a repeat of about 16^99999999, though one would have to
determine what shift-register taps to use for a maximal sequence (I have
a copy of a paper on the subject). However, it would not generate many
such numbers per second. Or maybe per minute. Or hour.

So the [off hand] repeat time would be more than the age of the universe,
independent of using once per second or once per hour?
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
Dr J R Stockton wrote on 01 dec 2008 in comp.lang.javascript:
That's nothing. My Delphi program LONGCALC could be programmed (in RPN)
to give a repeat of about 16^99999999, though one would have to
determine what shift-register taps to use for a maximal sequence (I have
a copy of a paper on the subject). However, it would not generate many
such numbers per second. Or maybe per minute. Or hour.

So the [off hand] repeat time would be more than the age of the universe,
independent of using once per second or once per hour?

It would be considerably longer than that, even with a machine that
could do one calculation per Planck time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top