We heavily use AJAX to allow immediate editing of all the page content. Pages do not require JavaScript to be read, but any work on a page requires full JavaScript functionality. The code sends POST and at times GET messages to the server to maintain the page as expected and keep the server synchronized.
For example, you are able to log in a page using AJAX so the page doesn't need to be fully refreshed. Similarly, editing the title of a page just requires a click on that title.
We have to think about several side effects of using AJAX:
When in edit mode (logged in) the user can click on items to edit them. In some cases, items are defined in an anchor (i.e. the logo of a website.) A click on the item holding the Ctrl key down enters the edit mode, otherwise the link is followed normally. [TBD]
If possible we want to show an Edit "frame" so the user is aware that the click is going to edit the data (i.e. when hovering the mouse and the Ctrl key is held down, this can work by adding a class to the body tag which is partially implemented--we ignore the Ctrl key scheme at this point.)
Small edits, such as changing a small set of flags (i.e. is page allowed in the XML sitemap?) should not include a Save button. When you click on the flag, the new state is sent to the server directly. If you have a screen with just flags, all can behave the same way.
However, a large text editor is probably better with a save button because users know of that one. Although we should allow for an auto-save, but that can cause problems of slowness (i.e. while auto-saving a draft on a slow client, the user may not be able to continue smooth editing...)
If the server fails handling a message (i.e. user doesn't have permission,) then an error is shown to the user at the time we receive the answer. The process sending the AJAX request must be pro-active in handling the error response, but that is like two lines of code: was there an error? yes, then call show messages.
If the server does not answer in time (i.e. timeout) then the timeout error is shown and probably a button allowing the user to try again.
If the user tries to leave a page before the AJAX process receives the answer to any message sent to the server, then a warning dialog is shown and the user has the choice to lose some or all of his changes or wait until the transaction replies were all received. Since this works by catching a message, the editor system handles this directly.
See also: e-Commerce feature
Interesting document about JavaScript and Private variables and functions by Crockford.
At this time the server_access plugin always sends a POST variable named _ajax set to the value 1. There seem to be a header sent by existing frameworks that tells servers that the request is an AJAX request. The header is:
X-Requested-With: XMLHttpRequest
We may want to change our request that way, although it may not work with GET requests.
See also: https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
Snap! Websites
An Open Source CMS System in C++