Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ajax in sync mode works with IE, does not work with Firefox

435 views
Skip to first unread message

zalek

unread,
Aug 28, 2008, 9:55:48 PM8/28/08
to
I am writing application with Ajax in sync mode - xmlHttp.open("GET",
url, false).
I noticed that in FireFox handler doesn't starts. It starts when I use
xmlHttp.open("GET", url,true).
I need to use it in sync mode. Any ideas what can I do?

Thanks,

Zalek.

Jorge

unread,
Aug 28, 2008, 11:05:00 PM8/28/08
to

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.

GArlington

unread,
Aug 29, 2008, 5:46:54 AM8/29/08
to
On Aug 29, 2:55 am, zalek <zalekbl...@hotmail.com> wrote:
> I am writing application with Ajax in sync mode - xmlHttp.open("GET",
> url, false).
> I noticed that in FireFox handler doesn't starts. It starts when I use
> xmlHttp.open("GET", url,true).
> I need to use it in sync mode.
WHY do you need to make AJAX call "in sync mode"? IT will only stop
doing anything else until it gets a response from the server...
So, just DO NOT do anything else until you get a response...
Or maybe I misunderstand what you are trying to do...

zalek

unread,
Aug 31, 2008, 8:11:08 AM8/31/08
to
On Aug 28, 11:05 pm, Jorge <jo...@jorgechamorro.com> wrote:
> On Aug 29, 3:55 am,zalek<zalekbl...@hotmail.com> wrote:
>
> > I am writing application withAjaxin sync mode - xmlHttp.open("GET",

> > url, false).
> > I noticed that in FireFox handler doesn't starts. It starts when I use
> > xmlHttp.open("GET", url,true).
> > I need to use it in sync mode. Any ideas what can I do?
>
> 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?

Jorge

unread,
Aug 31, 2008, 8:58:02 AM8/31/08
to
On Aug 31, 2:11 pm, zalek <zalekbl...@hotmail.com> wrote:
> xmlHttp.open("Get", url, true);

xmlHttp.open("Get", url, ** false **);

>
> Any ideas what to do?

Are you running this in FF3 ?

--
Jorge.

Jorge

unread,
Aug 31, 2008, 9:02:46 AM8/31/08
to
On Aug 31, 2:11 pm, zalek <zalekbl...@hotmail.com> wrote:
>
> xmlHttp.open("Get", url, true);

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.

zalek

unread,
Sep 3, 2008, 7:38:31 AM9/3/08
to

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

0 new messages