aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes using false in open() for Ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "using false in open() for Ajax" Watch "using false in open() for Ajax" New topic
Author

using false in open() for Ajax

RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi all,
I wanted to know if we can use false in the open() of XMLHttpRequest Object? If yes, then what is the advantage of using it. I think it would behave like a synchronous call(posting the whole form ???)..
Then writing down the Ajax code would be renderd useless. Any code snippet would be highly appreciated.
Please correct me where I am wrong.

Regards,
Roshani


Regards,<br />Roshani
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Yes you can, and it would be the same as sending a synchronous request, which means that the client will have to wait until the server finishes. I can't think of any use for this.


[My Blog]
All roads lead to JavaRanch
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Thanks Satou,
It cleared my doubt. But stil i wonder why it was given in the first place altogether, in the open()??? Anybody else please..
Regards,
Roshani
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Because people might want to make a synchronous request. Not sure what the question is here.

Eric
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi Eric,
Thanks for replying. I understand that in the open(), specifying "true" means we want to make a asyn call(Ajax call). Giving it to false would imply having syn call. This further implies that script waits for a reponse before continuing the script processing. The client will not be able to post any more data till the response has come back from the server.
So making a sync call is as good doing a postback. So where does the differnce lie in having a postback (Submit button) and writing down the whole code in the JS where it would be just making a sync call???

What could be any scernaio that I might want to use false in the open().

Regards,
Roshani
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
The answer is:
When you do not want to make a sych. request.

I am not sure what you are looking for here. I would not use a sych. request with the XMLHttpRequest onject since it can lock up a browser in certain situations.

Eric
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Thanks Eric,

I understood that using XMLHttpRequest object for sync calls would lock the UI while req is being made. Real life scenarios are very few where we use false in open().

By the way, Ajax in Action is lovely book. Thanks for such a great book.

Regards,
Roshani
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Some people want to lock the browser for doing things like a double combo (linked selects).

Something that requires processing before continuing is another example. Again, if I were to do something like that, I would normally do a post back since I would not want to risk browser freezing do to a problem.

Eric
 
Consider Paul's rocket mass heater.
 
subject: using false in open() for Ajax