Dec 31 2009

Google Closure’s idiocies: Ajax can’t be synchronous :(

Category: google closureDavide Zanotti @ 4:02 am

While I love Closure tools and the possibility to write a better organized and OOP based JavaScript, I’m facing some weakness and inexplicable choices in the library. The last discover is that is impossible to make synchronous ajax call using the provided classes, since I didn’t find nothing about synch/asynch options by reading API reference, I took a look to the source (xhrio.js), and I noticed this:

1
this.xhr_.open(method, url, true);  // Always async!

that true should be a parametric value which developers can set to true or false. Why forcing it to true???
I’m really disappointed :(

Tags: , ,

8 Responses to “Google Closure’s idiocies: Ajax can’t be synchronous :(”

  1. gsziszi says:

    ajax never can be synchronous:
    Asynchronous JavaScript and XML
    :)

  2. Davide Zanotti says:

    LOL :^) XmlHttpRequest can be opened both in synchronous (asynchronous flag set to “false”) than asynchronous mode (asynchronous flag set to “true”)

  3. gsziszi says:

    That is correct, but XmlHttpRequest is a method, AJAX is a technology based on that method.
    Otherwise, the JSON version of AJAX is AJAJ, however we use also XmlHttpRequest not JsonHttpRequest. So, we should be cautious when we use these words and abbreviations.

  4. Davide Zanotti says:

    XmlHttpRequest is not a method, is an object and it has methods like open(). By saying “ajax” I merely mean an xhr call to retrieve data on demand, this data can be plain text, json, xml or something else and can be retrieved synchronously or asynchronously, but from a generic point of view is always ajax (the term is very generic)… I hope I was clear :^)

  5. gsziszi says:

    I accept

  6. Maxence says:

    You can create a XmlHttpRequest with goog.net.XmlHttp and pass true in the third argument of the open method.

  7. Linus Ericsson says:

    The reason for this implementation quirk seems to be that Google Closure team (and all Google) really want that rich websites using Google’s tools should be blazing fast. Synchronous XHRs is (given javascripts single execution thread) bound to lock the whole execution until one get a reply and would give very sloppy performance for the gui.

  8. Joni says:

    It’s always a plueasre to hear from someone with expertise.

Leave a Reply