Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using false in open() for Ajax

 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because people might want to make a synchronous request. Not sure what the question is here.

Eric
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic