Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, when you say </p> <blockquote> <p>The ajaxMethod(), lets say is some kind of method defined in an external Java file</p> </blockquote> <p>I suppose you really mean external JavaScript file.</p> <p>When you send an Ajax request, you ask the browser to send a request to the server for you. This request on the server may take sometime and you don't want to "wait" on it. (This is the whole idea of Async requests - stuff in the background).<br> So you tell the browser, here send this request to the server. Don't bother me unless the server responds, and once the server responds (we have a "response"), call this method. This is called callback. The method is called at a later point, when the response comes.</p> <p>So the statement</p> <pre><code>x.ajaxMethod(param1,JScallBackFunction); </code></pre> <p>(assuming that it does gets a XmlHttpRequest, initializes it and calls the send method on it*) actually does two things: </p> <ol> <li>Sends the Ajax request </li> <li>Registers a call back function that will be called when the server responds (when we have an response). <code>JScallBackFunction</code> will be called when there is an response from the server.</li> </ol> <p>But since this is an asynchronous request, the browser does not "wait" instead it continues to the next statement (if there is one) after the Ajax call and executes it.</p> <p>So, <code>alert("Line after ajaxMethod");</code> will be executed immediately.</p> <p>*If this does not make any sense for you, this is how an Ajax request is actually "created" and "sent". <a href="http://code.google.com/edu/ajax/tutorials/ajax-tutorial.html" rel="nofollow">This article</a> may help you understand.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload