From: Mike on
Hello,
I get "A" and "B" but not alert(xmlHttp.readyState);
Plus, when debugging I am getting inconsistant results.
.................
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
alert("A");
xmlHttp.onreadystatechange=stateChanged;
alert("B");
}
function stateChanged()
{
alert(xmlHttp.readyState);
.................................
From: David Mark on
Mike wrote:
> Hello,
> I get "A" and "B" but not alert(xmlHttp.readyState);

Set the onreadystatechange property before calling send.

> Plus, when debugging I am getting inconsistant results.

http://www.jibbering.com/faq/faq_notes/clj_posts.html#ps1DontWork

A hint is that alerts can change the behavior of your code.

> ................
> xmlHttp.open("GET",url,true);
> xmlHttp.send(null);
> alert("A");
> xmlHttp.onreadystatechange=stateChanged;
> alert("B");
> }
> function stateChanged()
> {
> alert(xmlHttp.readyState);
> ................................
From: Mike on
On Mar 24, 7:23 pm, David Mark <dmark.cins...(a)gmail.com> wrote:
> Mike wrote:
> > Hello,
> > I get "A" and "B" but not  alert(xmlHttp.readyState);
>
> Set the onreadystatechange property before calling send.
>
> > Plus, when debugging I am getting inconsistant results.
>
> http://www.jibbering.com/faq/faq_notes/clj_posts.html#ps1DontWork
>
> A hint is that alerts can change the behavior of your code.
>
>
>
> > ................
> > xmlHttp.open("GET",url,true);
> > xmlHttp.send(null);
> > alert("A");
> > xmlHttp.onreadystatechange=stateChanged;
> > alert("B");
> > }
> > function stateChanged()
> > {
> >    alert(xmlHttp.readyState);
> > ................................- Hide quoted text -
>
> - Show quoted text -

Great, I Took the alerts out and it works.
Why does that happen?
From: Jorge on
On Mar 25, 1:02 am, Mike <ampel...(a)gmail.com> wrote:
>
> Great, I Took the alerts out and it works.

You should also set .onreadystatechange before calling .send() :

xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange= stateChanged;
xmlHttp.send(null);

--
Jorge.
From: Hans-Georg Michna on
On Wed, 24 Mar 2010 17:02:54 -0700 (PDT), Mike wrote:

>Great, I Took the alerts out and it works.
>Why does that happen?

Perhaps because the readystatechange event had already fired for
the last time before you clicked on the alert's OK button.

Check http://winhlp.com/node/684 for a functioning ajax routine
that has all the needed little stuff already. At least it can
serve as a starting point if you want to roll your own.

Ask here if any part of it is unclear.

Hans-Georg