Thanks,
Zalek.
The callback won't get called for synchronous XHR requests (there's no
need to).
But (AFAIK) nothing prevents you from calling it ("by hand") if you
need to, inmediatly after the .open(,,false) :
//xmlHttp.onreadystatechange= myCallback;
xmlHttp.open("GET", url, false);
myCallback();
--Jorge.
Guys,
Thanks for all responses. First I want to clarify why I need sysc mode
- I want to validate a form using Ajax. Yes - I know I can do this
convetional way, but I want to learn Ajax too and for me it is a good
oportunity.
I made a specjal code for FireFox and called request handler "by hand"
- but it did not work.
For FireFox I coded:
if (w_browser == "Firefox") {
xmlHttp.open("Get", url, true);
for(i=0;(i<9) || (xmlHttp.readyState == 4);i++){
handleHttpResponse() ;
}
}
function handleHttpResponse() {
alert("HTTPResponse state: = " + xmlHttp.readyState + " i=" + i) ;
[...]
I never saw readyState == 4, but I know that few times the server
defined on url was started. The problem is I need a message created by
the server Ajax is using.
Any ideas what to do?
xmlHttp.open("Get", url, ** false **);
>
> Any ideas what to do?
Are you running this in FF3 ?
--
Jorge.
xmlHttp.open("GET", url, ** false **);
> Any ideas what to do?
If you're running this in FF3, see cljs thread # ce635b45f594fc64 "A
bug in FF3's sync XHRs ?"
--
Jorge.
Thanks Jorge for your help,
I solved my problem and now my Ajax code is working in sync mode in FF
and IE. Just in case someone else will have a similar problem, here is
my code:
function validate_user_info() {
try {
// Firefox, Opera 8.0+, Safari
w_browser = "Firefox" ;
xmlHttp=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
w_browser = "IE" ;
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
w_browser = "not FireFox and not IE" ;
}
catch (e) {
alert("Your browser does not support AJAX!");
return ;
}
}
}
ajax_user_info();
return ;
}
function ajax_user_info() {
var url = "ajax_server.jsp?office=" +
document.forms[0].office.value +
"&car=" + document.forms[0].car.value ;
if (w_browser == "Firefox") {
xmlHttp.open("Get", url, false);
xmlHttp.onreadystatechange = handleHttpResponse;
}
else {
xmlHttp.open("Get", url, false);
xmlHttp.onreadystatechange = handleHttpResponse;
}
xmlHttp.send(null);
if (w_browser == "Firefox") {
i = 0;
while((i < 9) && (xmlHttp.readyState != 4) ) {
i++;
handleHttpResponse() ;
}
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200){
var message = xmlHttp.responseText ;
alert (message) ;
}
}
}
return ;
}
function handleHttpResponse() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200){
var message = xmlHttp.responseText ;
if (message.substr(0,2) != "ok") {
alert (message) ;
}
}
}
}
I am using code:
while((i < 9) && (xmlHttp.readyState != 4) ) {
i++;
handleHttpResponse() ;
}
in case Ajax server is slow, to gaine some time.
Zalek