Skip navigation

Tag Archives: ajax


Synchronous Request in Ajax means javascript will stop processing your program until a result has been obtained from the server. While the request is processing the browser is effectively frozen. The browser treats the call like an alert box or a prompt box only it doesn’t wait for input from the user but on input by the remote server. 99.99 of the time the response is quick and fast enough so that there isn’t any problems.

Synchronous request in ajax???? ajax itself means asynchronous javascript and xml. But why the hell do you need synchronous request from ajax???

Before going that a brief basics…

Asynchronous ajax will initiate a request to the server and then return control to the browser. After sometime you can still manage the result return from server(means server responds, timedout, error, etc.).

Synchronous request in ajax means javascript will stop processing your program until a result has been obtained from the server. Until it is processing the browser is frozen.

Now back to topic…

When this asynchronous behaviour seems good, still we need synchronous behaviour at certain situations. Say for example if a user needs to signout after check out something online. In this case it is better to synchronize ajax call, otherwise before server return, user may navigate to other page which is not good.

Right. How to sjax (synchronous javascript and xml)?

In open method of ajax object, set thrid parameter as false. thats it.

Here goes an example

function getAsset(url) {
  if (window.XMLHttpRequest) {
    xhr=new XMLHttpRequest();
  } else {
    xhr=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (xhr) {
    xhr.open("GET", url, false);
    xhr.send(null);
    return xhr.responseText;
  } else {
    return false;
  }
}
var asset = getAsset("http://domain.com/file.ext");

We all know about pros of ajax. Here is a list of cons

  • Breaking the back button
  • A big problem for spidering and search engines
  • Not using links I can pass to friends or bookmark
  • Not giving immediate visual cues for interaction
  • Too much code makes the browser slow
  • Blinking and changing parts of the page unexpectedly
  • Leaving offline (poor connectivity) people behind
  • Asynchronously performing batch operations
  • Changing state with links (Get Requests)
  • Non obvious navigation to drive non obvious result

Of course, these are main concerns of interaction designer.