Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not really a problem. AJAX is asynchronous by nature (<strong>Asynchronous</strong> Javascript and XML). You will have to wait until you get a response from the server to update your UI.</p> <p>If you <em>must</em> update the UI immediately, you can create an element with a placeholder ID that you can then update with the actual ID once the server responds.</p> <p><strong>UPDATE</strong></p> <p>This is in response to your comment. Webapps are not purely client-side applications. They fit into the client-server paradigm. You can try using a synchronous post, but this has the side-effect of tying up the browser until the server responds (this is due to the fact that Javascript is single-threaded).</p> <p>That being said, the response from the server should be pretty quick unless your network is slow or if whatever post your sending to the server results in some computationally-intensive operation.</p> <p>Going by the placeholder route will (as you have realized) result in all sorts of new problems that you have to deal with. You have to ensure that they are unique. Now what if they perform some operation on the client-side element before the server responds with an id? The server won't know what the placeholder id means. There are ways around this (queuing requests is one way), but it will make your code a whole lot more complicated. I don't think the tradeoff is worth it just to make the UI update faster. </p> <p>An option is to provide some visual feedback to the user that the app is "working" (i.e., while you are waiting for a response from the server). A spinner, for example.</p> <p>As far as stacking the AJAX requests, that is one approach that you can take using the <a href="http://benalman.com/projects/jquery-message-queuing-plugin/" rel="nofollow">jQuery message-queuing</a> plugin.</p>
    singulars
    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.
 

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