How To Get JavaScript Conditional Statement To Wait for XMLHTTPResponse?

P

pbd22

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.
 
D

David Mark

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.
 
P

pbd22

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.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top