late variable value via ajax connection

I

info

hi.

I've got a serious issue in my code that i can't figure out. I've got
pretty big code of entire site and a bug in this very place:

aut="";
try{
zaptmp='zaloguj.php?h='+haslo+'&co='+wdp;
poljs.open('GET',zaptmp,true);
poljs.onreadystatechange=function(){
if (poljs.readyState==4) {
aut=poljs.responseText;
document.title=aut;
}
}
poljs.send(null);
}
catch(zonka){
aut="error connecting server: " +
zonk.description;
};
// alert(aut);
if(aut=="ok"){
.......

so:
- try-catch is about to authenticate user via zaloguj.php (server side
works perfect and returns right status every time- let's make it
simple:status can be "ok" or "not ok")

- if(aut=="ok"){ - there is some code to execute if the user
authentication is ok.

the problem is that if(aut... never pass - aut variable has always
empty value in that place, but document.title changes to "ok" or "not
ok" so zaloguj.php responds as it should.
if I uncomment alert above, and the script waits till i press alerts
ok button, if(aut works perfectly.

It looks like the if(aut is beeing processed before poljs get the
response. I can move if(aut inside try-catch but i don't understand
why doesn't it work right now.

If anyone could confirm or make it clear what the problem is?


thanks in advance
cac
 
D

David Mark

hi.

I've got a serious issue in my code that i can't figure out. I've got
pretty big code of entire site and a bug in this very place:

aut="";
try{
zaptmp='zaloguj.php?h='+haslo+'&co='+wdp;
poljs.open('GET',zaptmp,true);
poljs.onreadystatechange=function(){
if (poljs.readyState==4) {
aut=poljs.responseText;
document.title=aut;
}
}
poljs.send(null);
}
catch(zonka){
aut="error connecting server: " +
zonk.description;

You've got a problem here. What is "zonk?"
};
// alert(aut);
if(aut=="ok"){
......

Do you not realize what the "A" in Ajax stands for? Call the
authenticate code from your readystatechange handler.
 
I

info

hi again.

zonk is only misspelling from error catch zonka that came out during
bug search. the real problem was i didn't realize that ajax
connection goes on its own thread. of course it looks perfectly logic
right now but it did not yesterday:)

thanks for tip - everything works now as it should


best regards
cac
 

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

Similar Threads


Members online

Forum statistics

Threads
474,155
Messages
2,570,871
Members
47,401
Latest member
CliffGrime

Latest Threads

Top