AJAX Toolkit allows to issue synchronous or asynchronous calls. Asynchronous calls allow the client side process to continue, waiting for a call back from the server. To issue an asynchronous call, you must include an additional parameter with the API call, referred to as a callback function. Once the result is ready, the server invokes the callback method with the result.
Synchronous syntax:
sforce.connection.method("arg1","arg2", ...);
e.g:
sforce.connection.login("MyName@MyOrg.com","myPassword1");
Asynchronous syntax:
method("arg1","arg2", ..., callback_method);
For example:
var callback = {onSuccess: handleSuccess, onFailure: handleFailure};
function handleSuccess(result) {}
function handleFailure(error) {}
sforce.connection.query("Select name from Account", callback);