Skip to content
This repository
Browse code

MINOR Added PJAX and ajax redirect documentation to cms-archirecture …

…reference guide
  • Loading branch information...
commit 0fd7ce6a1ecfca5fe4069bc5ffcb8e86ccad6108 1 parent 5cfbac6
Ingo Schommer authored

Showing 1 changed file with 16 additions and 0 deletions. Show diff stats Hide diff stats

  1. 16  docs/en/reference/cms-architecture.md
16  docs/en/reference/cms-architecture.md
Source Rendered
@@ -179,6 +179,22 @@ Alternatively, form-related Ajax calls can be invoked through their own wrappers
179 179
 which don't cause history events and hence allow callbacks: `$('.cms-content').loadForm()`
180 180
 and `$('.cms-content').submitForm()`.
181 181
 
  182
+Within the PHP logic, the `[api:PjaxResponseNegotiator]` class determines which view is rendered.
  183
+Through a custom `X-Pjax` HTTP header, the client can declare which view he's expecting,
  184
+through identifiers like `CurrentForm` or `Content` (see `[api:LeftAndMain->getResponseNegotiator()]`).
  185
+These identifiers are passed to `loadPanel()` via the `pjax` data option.
  186
+
  187
+## Ajax Redirects
  188
+
  189
+Sometimes, a server response represents a new URL state, e.g. when submitting an "add record" form,
  190
+the resulting view will be the edit form of the new record. On non-ajax submissions, that's easily
  191
+handled through a HTTP redirection. On ajax submissions, browsers handle these redirects
  192
+transparently, so the CMS JavaScript doesn't know about them (or the new URL).
  193
+To work around this, we're using a custom `X-ControllerURL` HTTP response header
  194
+which can declare a new URL. If this header is set, the CMS JavaScript will
  195
+push the URL to its history stack, causing the logic to fetch it in a subsequent ajax request.
  196
+Note: To avoid double processing, the first response body is usually empty.
  197
+
182 198
 ## State through HTTP response metadata
183 199
 
184 200
 By loading mostly HTML responses, we don't have an easy way to communicate

0 notes on commit 0fd7ce6

Please sign in to comment.
Something went wrong with that request. Please try again.