Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How To Get JavaScript Conditional Statement To Wait for XMLHTTPResponse?

Reply
Thread Tools

How To Get JavaScript Conditional Statement To Wait for XMLHTTPResponse?

 
 
pbd22
Guest
Posts: n/a
 
      12-02-2008

Hi.

It seems my xmlhttp response is taking too long. I have something like
this:

try
{
if (a === "")
err += "some error";

if (b==="")
err += "some error";

if (c==="")
{
err += "some error";
}
else
{
// use an xmlhttp request to compare a condition
// that must be evaluated from the server. the response
// is true or false.
}

}
catch{}

finally{

if (err ==="")
//submit the form
else
//let the user know about the errors.
}

THE PROBLEM is that the logic does not publish the response of the
Ajax request
because the round-trip takes too long. I have tested this by adding an
alert. If the alert
fires and then I click off the alert dialog, the appropriate response
from the Ajax request
is in the error list. But, otherwise, it seems like the time it takes
to respond is omitting the
response in the error list.

Is there a way in JavaScript in an If/Else scenario to force getting
the appropriate response
from the Ajax request before the next code block is evaluated?

Thanks in advance.
 
Reply With Quote
 
 
 
 
David Mark
Guest
Posts: n/a
 
      12-02-2008
On Dec 2, 2:52*pm, pbd22 <dush...@gmail.com> wrote:
> Hi.
>
> It seems my xmlhttp response is taking too long. I have something like
> this:
>
> try
> {
> if (a === "")
> err += "some error";
>
> if (b==="")
> err += "some error";
>
> if (c==="")
> {
> err += "some error";}
>
> else
> {
> // use an xmlhttp request to compare a condition
> // that must be evaluated from the server. the response
> // is true or false.
>
> }
> }
>
> catch{}
>
> finally{
>
> if (err ==="")
> //submit the form
> else
> //let the user know about the errors.
>
> }
>
> THE PROBLEM is that the logic does not publish the response of the
> Ajax request
> because the round-trip takes too long. I have tested this by adding an
> alert. If the alert
> fires and then I click off the alert dialog, the appropriate response
> from the Ajax request
> is in the error list. But, otherwise, it seems like the time it takes
> to respond is omitting the
> response in the error list.
>
> Is there a way in JavaScript in an If/Else scenario to force getting
> the appropriate response
> from the Ajax request before the next code block is evaluated?
>
> Thanks in advance.


You would have to use a synchronous request, which is a very bad idea
for a browser script. Change your design to suit an asynchronous
request.
 
Reply With Quote
 
 
 
 
pbd22
Guest
Posts: n/a
 
      12-03-2008
On Dec 2, 1:12*pm, David Mark <dmark.cins...@gmail.com> wrote:
> On Dec 2, 2:52*pm, pbd22 <dush...@gmail.com> wrote:
>
>
>
> > Hi.

>
> > It seems my xmlhttp response is taking too long. I have something like
> > this:

>
> > try
> > {
> > if (a === "")
> > err += "some error";

>
> > if (b==="")
> > err += "some error";

>
> > if (c==="")
> > {
> > err += "some error";}

>
> > else
> > {
> > // use an xmlhttp request to compare a condition
> > // that must be evaluated from the server. the response
> > // is true or false.

>
> > }
> > }

>
> > catch{}

>
> > finally{

>
> > if (err ==="")
> > //submit the form
> > else
> > //let the user know about the errors.

>
> > }

>
> > THE PROBLEM is that the logic does not publish the response of the
> > Ajax request
> > because the round-trip takes too long. I have tested this by adding an
> > alert. If the alert
> > fires and then I click off the alert dialog, the appropriate response
> > from the Ajax request
> > is in the error list. But, otherwise, it seems like the time it takes
> > to respond is omitting the
> > response in the error list.

>
> > Is there a way in JavaScript in an If/Else scenario to force getting
> > the appropriate response
> > from the Ajax request before the next code block is evaluated?

>
> > Thanks in advance.

>
> You would have to use a synchronous request, which is a very bad idea
> for a browser script. *Change your design to suit an asynchronous
> request.


OK, thanks. Would you mind providing some pseudo code to give me a
sense of things?

Thanks again.
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      12-03-2008
On Dec 3, 3:00*pm, pbd22 <dush...@gmail.com> wrote:
> On Dec 2, 1:12*pm, David Mark <dmark.cins...@gmail.com> wrote:
>
>
>
> > On Dec 2, 2:52*pm, pbd22 <dush...@gmail.com> wrote:

>
> > > Hi.

>
> > > It seems my xmlhttp response is taking too long. I have something like
> > > this:

>
> > > try
> > > {
> > > if (a === "")
> > > err += "some error";

>
> > > if (b==="")
> > > err += "some error";

>
> > > if (c==="")
> > > {
> > > err += "some error";}

>
> > > else
> > > {
> > > // use an xmlhttp request to compare a condition
> > > // that must be evaluated from the server. the response
> > > // is true or false.

>
> > > }
> > > }

>
> > > catch{}

>
> > > finally{

>
> > > if (err ==="")
> > > //submit the form
> > > else
> > > //let the user know about the errors.

>
> > > }

>
> > > THE PROBLEM is that the logic does not publish the response of the
> > > Ajax request
> > > because the round-trip takes too long. I have tested this by adding an
> > > alert. If the alert
> > > fires and then I click off the alert dialog, the appropriate response
> > > from the Ajax request
> > > is in the error list. But, otherwise, it seems like the time it takes
> > > to respond is omitting the
> > > response in the error list.

>
> > > Is there a way in JavaScript in an If/Else scenario to force getting
> > > the appropriate response
> > > from the Ajax request before the next code block is evaluated?

>
> > > Thanks in advance.

>
> > You would have to use a synchronous request, which is a very bad idea
> > for a browser script. *Change your design to suit an asynchronous
> > request.

>
> OK, thanks. Would you mind providing some pseudo code to give me a
> sense of things?
>
> Thanks again.


See the FAQ notes for an example.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to wait with timeout on conditional variable in ruby 1.9 Sharat Mohan Ruby 0 02-13-2009 01:24 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM
How to make "fork/wait" to WAIT longer? Huey C Programming 1 03-01-2004 02:01 PM



Advertisments
 



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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57