Zend_Controller-ActionHelpers-ContextSwitch.xml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.controller.actionhelpers.contextswitch">
  4. <title>ContextSwitch and AjaxContext</title>
  5. <para>
  6. The <code>ContextSwitch</code> action helper is intended for
  7. facilitating returning different response formats on request.
  8. The <code>AjaxContext</code> helper is a specialized version of
  9. <code>ContextSwitch</code> that facilitates returning responses
  10. to XmlHttpRequests.
  11. </para>
  12. <para>
  13. To enable either one, you must provide hinting in your controller as to
  14. what actions can respond to which contexts. If an incoming request
  15. indicates a valid context for the given action, the helper will then:
  16. </para>
  17. <itemizedlist>
  18. <listitem><para>
  19. Disable layouts, if enabled.
  20. </para></listitem>
  21. <listitem><para>
  22. Set an alternate view suffix, effectively requiring a separate
  23. view script for the context.
  24. </para></listitem>
  25. <listitem><para>
  26. Send appropriate response headers for the context desired.
  27. </para></listitem>
  28. <listitem><para>
  29. Optionally, call specified callbacks to setup the context and/or
  30. perform post-processing.
  31. </para></listitem>
  32. </itemizedlist>
  33. <para>
  34. As an example, let's consider the following controller:
  35. </para>
  36. <programlisting role="php"><![CDATA[
  37. class NewsController extends Zend_Controller_Action
  38. {
  39. /**
  40. * Landing page; forwards to listAction()
  41. */
  42. public function indexAction()
  43. {
  44. $this->_forward('list');
  45. }
  46. /**
  47. * List news items
  48. */
  49. public function listAction()
  50. {
  51. }
  52. /**
  53. * View a news item
  54. */
  55. public function viewAction()
  56. {
  57. }
  58. }
  59. ]]></programlisting>
  60. <para>
  61. Let's say that we want the <code>listAction()</code> to also be
  62. available in an XML format. Instead of creating a different action, we
  63. can hint that it can return an XML response:
  64. </para>
  65. <programlisting role="php"><![CDATA[
  66. class NewsController extends Zend_Controller_Action
  67. {
  68. public function init()
  69. {
  70. $contextSwitch = $this->_helper->getHelper('contextSwitch');
  71. $contextSwitch->addActionContext('list', 'xml')
  72. ->initContext();
  73. }
  74. // ...
  75. }
  76. ]]></programlisting>
  77. <para>
  78. What this will do is:
  79. </para>
  80. <itemizedlist>
  81. <listitem><para>
  82. Set the 'Content-Type' response header to 'text/xml'.
  83. </para></listitem>
  84. <listitem><para>
  85. Change the view suffix to 'xml.phtml' (or, if you use an
  86. alternate view suffix, 'xml.[your suffix]').
  87. </para></listitem>
  88. </itemizedlist>
  89. <para>
  90. Now, you'll need to create a new view script, 'news/list.xml.phtml',
  91. which will create and render the XML.
  92. </para>
  93. <para>
  94. To determine if a request should initiate a context switch, the helper
  95. checks for a token in the request object. By default, it looks for the
  96. 'format' parameter, though this may be configured. This means that, in
  97. most cases, to trigger a context switch, you can add a 'format'
  98. parameter to your request:
  99. </para>
  100. <itemizedlist>
  101. <listitem><para>
  102. Via URL parameter: <code>/news/list/format/xml</code> (recall,
  103. the default routing schema allows for arbitrary key/value pairs
  104. following the action)
  105. </para></listitem>
  106. <listitem><para>
  107. Via GET parameter: <code>/news/list?format=xml</code>
  108. </para></listitem>
  109. </itemizedlist>
  110. <para>
  111. <code>ContextSwitch</code> allows you to specify arbitrary contexts,
  112. including what suffix change will occur (if any), any response headers
  113. that should be sent, and arbitrary callbacks for initialization and post
  114. processing.
  115. </para>
  116. <sect4 id="zend.controller.actionhelpers.contextswitch.contexts">
  117. <title>Default Contexts Available</title>
  118. <para>
  119. By default, two contexts are available to the
  120. <code>ContextSwitch</code> helper: json and xml.
  121. </para>
  122. <itemizedlist>
  123. <listitem>
  124. <para>
  125. <emphasis>JSON</emphasis>. The JSON context sets the
  126. 'Content-Type' response header to 'application/json', and
  127. the view script suffix to 'json.phtml'.
  128. </para>
  129. <para>
  130. By default, however, no view script is required. It will
  131. simply serialize all view variables, and emit the JSON
  132. response immediately.
  133. </para>
  134. <para>
  135. This behaviour can be disabled by turning off auto-JSON
  136. serialization:
  137. </para>
  138. <programlisting role="php"><![CDATA[
  139. $this->_helper->contextSwitch()->setAutoJsonSerialization(false);
  140. ]]></programlisting>
  141. </listitem>
  142. <listitem>
  143. <para>
  144. <emphasis>XML</emphasis>. The XML context sets the
  145. 'Content-Type' response header to 'text/xml', and the view
  146. script suffix to 'xml.phtml'. You will need to create a new
  147. view script for the context.
  148. </para>
  149. </listitem>
  150. </itemizedlist>
  151. </sect4>
  152. <sect4 id="zend.controller.actionhelpers.contextswitch.custom">
  153. <title>Creating Custom Contexts</title>
  154. <para>
  155. Sometimes, the default contexts are not enough. For instance, you
  156. may wish to return YAML, or serialized PHP, an RSS or ATOM feed,
  157. etc. <code>ContextSwitch</code> allows you to do so.
  158. </para>
  159. <para>
  160. The easiest way to add a new context is via the
  161. <code>addContext()</code> method. This method takes two arguments,
  162. the name of the context, and an array specification. The
  163. specification should include one or more of the following:
  164. </para>
  165. <itemizedlist>
  166. <listitem>
  167. <para><emphasis>suffix</emphasis>: the suffix to prepend to the
  168. default view suffix as registered in the ViewRenderer.</para>
  169. </listitem>
  170. <listitem>
  171. <para><emphasis>headers</emphasis>: an array of header/value
  172. pairs you wish sent as part of the response.</para>
  173. </listitem>
  174. <listitem>
  175. <para><emphasis>callbacks</emphasis>: an array containing one or
  176. more of the keys 'init' or 'post', pointing to valid PHP
  177. callbacks that can be used for context initialization and post
  178. processing.</para>
  179. <para>Initialization callbacks occur when the context is
  180. detected by <code>ContextSwitch</code>. You can use it to
  181. perform arbitrary logic that should occur. As an example,
  182. the JSON context uses a callback to disable the ViewRenderer
  183. when auto-JSON serialization is on.</para>
  184. <para>Post processing occurs during the action's
  185. <code>postDispatch()</code> routine, and can be used to perform
  186. arbitrary logic. As an example, the JSON context uses a callback
  187. to determine if auto-JSON serialization is on; if so, it
  188. serializes the view variables to JSON and sends the response,
  189. but if not, it re-enables the ViewRenderer.</para>
  190. </listitem>
  191. </itemizedlist>
  192. <para>
  193. There are a variety of methods for interacting with contexts:
  194. </para>
  195. <itemizedlist>
  196. <listitem><para>
  197. <code>addContext($context, array $spec)</code>: add a new
  198. context. Throws an exception if the context already exists.
  199. </para></listitem>
  200. <listitem><para>
  201. <code>setContext($context, array $spec)</code>: add a new
  202. context or overwrite an existing context. Uses the same
  203. specification as <code>addContext()</code>.
  204. </para></listitem>
  205. <listitem><para>
  206. <code>addContexts(array $contexts)</code>: add many contexts at
  207. once. The <code>$contexts</code> array should be an array of
  208. context/specification pairs. If any of the contexts already
  209. exists, it will throw an exception.
  210. </para></listitem>
  211. <listitem><para>
  212. <code>setContexts(array $contexts)</code>: add new contexts and
  213. overwrite existing ones. Uses the same specification as
  214. <code>addContexts()</code>.
  215. </para></listitem>
  216. <listitem><para>
  217. <code>hasContext($context)</code>: returns true if the context
  218. exists, false otherwise.
  219. </para></listitem>
  220. <listitem><para> <code>getContext($context)</code>: retrieve a
  221. single context by name. Returns an array following the
  222. specification used in <code>addContext()</code>.
  223. </para></listitem>
  224. <listitem><para>
  225. <code>getContexts()</code>: retrieve all contexts. Returns an
  226. array of context/specification pairs.
  227. </para></listitem>
  228. <listitem><para>
  229. <code>removeContext($context)</code>: remove a single context by
  230. name. Returns true if successful, false if the context was not
  231. found.
  232. </para></listitem>
  233. <listitem><para>
  234. <code>clearContexts()</code>: remove all contexts.
  235. </para></listitem>
  236. </itemizedlist>
  237. </sect4>
  238. <sect4 id="zend.controller.actionhelpers.contextswitch.actions">
  239. <title>Setting Contexts Per Action</title>
  240. <para>
  241. There are two mechanisms for setting available contexts. You can
  242. either manually create arrays in your controller, or use several
  243. methods in <code>ContextSwitch</code> to assemble them.
  244. </para>
  245. <para>
  246. The principle method for adding action/context relations is
  247. <code>addActionContext()</code>. It expects two arguments, the
  248. action to which the context is being added, and either the name of a
  249. context or an array of contexts. As an example, consider the
  250. following controller class:
  251. </para>
  252. <programlisting role="php"><![CDATA[
  253. class FooController extends Zend_Controller_Action
  254. {
  255. public function listAction()
  256. {
  257. }
  258. public function viewAction()
  259. {
  260. }
  261. public function commentsAction()
  262. {
  263. }
  264. public function updateAction()
  265. {
  266. }
  267. }
  268. ]]></programlisting>
  269. <para>
  270. Let's say we wanted to add an XML context to the 'list' action, and
  271. XML and JSON contexts to the 'comments' action. We could do so in
  272. the <code>init()</code> method:
  273. </para>
  274. <programlisting role="php"><![CDATA[
  275. class FooController extends Zend_Controller_Action
  276. {
  277. public function init()
  278. {
  279. $this->_helper->contextSwitch()
  280. ->addActionContext('list', 'xml')
  281. ->addActionContext('comments', array('xml', 'json'))
  282. ->initContext();
  283. }
  284. }
  285. ]]></programlisting>
  286. <para>
  287. Alternately, you could simply define the array property
  288. <code>$contexts</code>:
  289. </para>
  290. <programlisting role="php"><![CDATA[
  291. class FooController extends Zend_Controller_Action
  292. {
  293. public $contexts = array(
  294. 'list' => array('xml'),
  295. 'comments' => array('xml', 'json')
  296. );
  297. public function init()
  298. {
  299. $this->_helper->contextSwitch()->initContext();
  300. }
  301. }
  302. ]]></programlisting>
  303. <para>
  304. The above is less overhead, but also prone to potential errors.
  305. </para>
  306. <para>
  307. The following methods can be used to build the context mappings:
  308. </para>
  309. <itemizedlist>
  310. <listitem>
  311. <para>
  312. <code>addActionContext($action, $context)</code>: marks one
  313. or more contexts as available to an action. If mappings
  314. already exists, simply appends to those mappings.
  315. <code>$context</code> may be a single context, or an array
  316. of contexts.
  317. </para>
  318. <para>
  319. A value of <code>true</code> for the context will mark
  320. all available contexts as available for the action.
  321. </para>
  322. <para>
  323. An empty value for $context will disable all contexts for
  324. the given action.
  325. </para>
  326. </listitem>
  327. <listitem><para>
  328. <code>setActionContext($action, $context)</code>: marks one
  329. or more contexts as available to an action. If mappings
  330. already exists, it replaces them with those specified.
  331. <code>$context</code> may be a single context, or an array
  332. of contexts.
  333. </para></listitem>
  334. <listitem><para>
  335. <code>addActionContexts(array $contexts)</code>: add several
  336. action/context pairings at once. <code>$contexts</code>
  337. should be an associative array of action/context pairs. It
  338. proxies to <code>addActionContext()</code>, meaning that if
  339. pairings already exist, it appends to them.
  340. </para></listitem>
  341. <listitem><para>
  342. <code>setActionContexts(array $contexts)</code>: acts like
  343. <code>addActionContexts()</code>, but overwrites existing
  344. action/context pairs.
  345. </para></listitem>
  346. <listitem><para>
  347. <code>hasActionContext($action, $context)</code>: determine
  348. if a particular action has a given context.
  349. </para></listitem>
  350. <listitem><para>
  351. <code>getActionContexts($action = null)</code>: returns
  352. either all contexts for a given action, or all
  353. action/context pairs.
  354. </para></listitem>
  355. <listitem><para>
  356. <code>removeActionContext($action, $context)</code>: remove
  357. one or more contexts from a given action.
  358. <code>$context</code> may be a single context or an array of
  359. contexts.
  360. </para></listitem>
  361. <listitem><para>
  362. <code>clearActionContexts($action = null)</code>: remove all
  363. contexts from a given action, or from all actions with
  364. contexts.
  365. </para></listitem>
  366. </itemizedlist>
  367. </sect4>
  368. <sect4 id="zend.controller.actionhelpers.contextswitch.initcontext">
  369. <title>Initializing Context Switching</title>
  370. <para>
  371. To initialize context switching, you need to call
  372. <code>initContext()</code> in your action controller:
  373. </para>
  374. <programlisting role="php"><![CDATA[
  375. class NewsController extends Zend_Controller_Action
  376. {
  377. public function init()
  378. {
  379. $this->_helper->contextSwitch()->initContext();
  380. }
  381. }
  382. ]]></programlisting>
  383. <para>
  384. In some cases, you may want to force the context used; for instance,
  385. you may only want to allow the XML context if context switching is
  386. activated. You can do so by passing the context to
  387. <code>initContext()</code>:
  388. </para>
  389. <programlisting role="php"><![CDATA[
  390. $contextSwitch->initContext('xml');
  391. ]]></programlisting>
  392. </sect4>
  393. <sect4 id="zend.controller.actionhelpers.contextswitch.misc">
  394. <title>Additional Functionality</title>
  395. <para>
  396. A variety of methods can be used to alter the behaviour of the
  397. <code>ContextSwitch</code> helper. These include:
  398. </para>
  399. <itemizedlist>
  400. <listitem>
  401. <para>
  402. <code>setAutoJsonSerialization($flag)</code>: By default,
  403. JSON contexts will serialize any view variables to JSON
  404. notation and return this as a response. If you wish to
  405. create your own response, you should turn this off; this
  406. needs to be done prior to the call to
  407. <code>initContext()</code>.
  408. </para>
  409. <programlisting role="php"><![CDATA[
  410. $contextSwitch->setAutoJsonSerialization(false);
  411. $contextSwitch->initContext();
  412. ]]></programlisting>
  413. <para>
  414. You can retrieve the value of the flag with
  415. <code>getAutoJsonSerialization()</code>.
  416. </para>
  417. </listitem>
  418. <listitem>
  419. <para>
  420. <code>setSuffix($context, $suffix,
  421. $prependViewRendererSuffix)</code>: With this method,
  422. you can specify a different suffix to use for a given
  423. context. The third argument is used to indicate whether or
  424. not to prepend the current ViewRenderer suffix with the new
  425. suffix; this flag is enabled by default.
  426. </para>
  427. <para>
  428. Passing an empty value to the suffix will cause only the
  429. ViewRenderer suffix to be used.
  430. </para>
  431. </listitem>
  432. <listitem>
  433. <para>
  434. <code>addHeader($context, $header, $content)</code>: Add a
  435. response header for a given context. <code>$header</code> is
  436. the header name, and <code>$content</code> is the value to
  437. pass for that header.
  438. </para>
  439. <para>
  440. Each context can have multiple headers;
  441. <code>addHeader()</code> adds additional headers to the
  442. context's header stack.
  443. </para>
  444. <para>
  445. If the <code>$header</code> specified already exists for the
  446. context, an exception will be thrown.
  447. </para>
  448. </listitem>
  449. <listitem>
  450. <para>
  451. <code>setHeader($context, $header, $content)</code>:
  452. <code>setHeader()</code> acts just like
  453. <code>addHeader()</code>, except it allows you to overwrite
  454. existing context headers.
  455. </para>
  456. </listitem>
  457. <listitem>
  458. <para>
  459. <code>addHeaders($context, array $headers)</code>: Add
  460. multiple headers at once to a given context. Proxies to
  461. <code>addHeader()</code>, so if the header already exists,
  462. an exception will be thrown. <code>$headers</code> is an
  463. array of header/context pairs.
  464. </para>
  465. </listitem>
  466. <listitem>
  467. <para>
  468. <code>setHeaders($context, array $headers.)</code>: like
  469. <code>addHeaders()</code>, except it proxies to
  470. <code>setHeader()</code>, allowing you to overwrite existing
  471. headers.
  472. </para>
  473. </listitem>
  474. <listitem>
  475. <para>
  476. <code>getHeader($context, $header)</code>: retrieve the
  477. value of a header for a given context. Returns null if not
  478. found.
  479. </para>
  480. </listitem>
  481. <listitem>
  482. <para>
  483. <code>removeHeader($context, $header)</code>: remove a
  484. single header for a given context.
  485. </para>
  486. </listitem>
  487. <listitem>
  488. <para>
  489. <code>clearHeaders($context, $header)</code>: remove all
  490. headers for a given context.
  491. </para>
  492. </listitem>
  493. <listitem>
  494. <para>
  495. <code>setCallback($context, $trigger, $callback)</code>: set
  496. a callback at a given trigger for a given context. Triggers
  497. may be either 'init' or 'post' (indicating callback will be
  498. called at either context initialization or postDispatch).
  499. <code>$callback</code> should be a valid PHP callback.
  500. </para>
  501. </listitem>
  502. <listitem>
  503. <para>
  504. <code>setCallbacks($context, array $callbacks)</code>: set
  505. multiple callbacks for a given context. <code>$callbacks</code>
  506. should be trigger/callback pairs. In actuality, the most callbacks
  507. that can be registered are two, one for initialization and
  508. one for post processing.
  509. </para>
  510. </listitem>
  511. <listitem>
  512. <para>
  513. <code>getCallback($context, $trigger)</code>: retrieve a
  514. callback for a given trigger in a given context.
  515. </para>
  516. </listitem>
  517. <listitem>
  518. <para>
  519. <code>getCallbacks($context)</code>: retrieve all callbacks
  520. for a given context. Returns an array of trigger/callback
  521. pairs.
  522. </para>
  523. </listitem>
  524. <listitem>
  525. <para>
  526. <code>removeCallback($context, $trigger)</code>: remove a
  527. callback for a given trigger and context.
  528. </para>
  529. </listitem>
  530. <listitem>
  531. <para>
  532. <code>clearCallbacks($context)</code>: remove all
  533. callbacks for a given context.
  534. </para>
  535. </listitem>
  536. <listitem>
  537. <para>
  538. <code>setContextParam($name)</code>: set the request
  539. parameter to check when determining if a context switch has
  540. been requested. The value defaults to 'format', but this
  541. accessor can be used to set an alternate value.
  542. </para>
  543. <para>
  544. <code>getContextParam()</code> can be used to retrieve the
  545. current value.
  546. </para>
  547. </listitem>
  548. <listitem>
  549. <para>
  550. <code>setAutoDisableLayout($flag)</code>: By default,
  551. layouts are disabled when a context switch occurs; this is
  552. because typically layouts will only be used for returning
  553. normal responses, and have no meaning in alternate contexts.
  554. However, if you wish to use layouts (perhaps you may have a
  555. layout for the new context), you can change this behaviour
  556. by passing a false value to
  557. <code>setAutoDisableLayout()</code>. You should do this
  558. <emphasis>before</emphasis> calling
  559. <code>initContext()</code>.
  560. </para>
  561. <para>
  562. To get the value of this flag, use the accessor
  563. <code>getAutoDisableLayout()</code>.
  564. </para>
  565. </listitem>
  566. <listitem>
  567. <para>
  568. <code>getCurrentContext()</code> can be used to determine
  569. what context was detected, if any. This returns null if no
  570. context switch occurred, or if called before
  571. <code>initContext()</code> has been invoked.
  572. </para>
  573. </listitem>
  574. </itemizedlist>
  575. </sect4>
  576. <sect4 id="zend.controller.actionhelpers.contextswitch.ajaxcontext">
  577. <title>AjaxContext Functionality</title>
  578. <para>
  579. The <code>AjaxContext</code> helper extends
  580. <code>ContextSwitch</code>, so all of the functionality listed for
  581. <code>ContextSwitch</code> is available to it. There are a few key
  582. differences, however.
  583. </para>
  584. <para>
  585. First, it uses a different action controller property for
  586. determining contexts, <code>$ajaxable</code>. This is so you can
  587. have different contexts used for AJAX versus normal HTTP requests.
  588. The various <code>*ActionContext*()</code> methods of
  589. <code>AjaxContext</code> will write to this property.
  590. </para>
  591. <para>
  592. Second, it will only trigger if an XmlHttpRequest has occurred, as
  593. determined by the request object's <code>isXmlHttpRequest()</code>
  594. method. Thus, if the context parameter ('format') is passed in the
  595. request, but the request was not made as an XmlHttpRequest, no
  596. context switch will trigger.
  597. </para>
  598. <para>
  599. Third, <code>AjaxContext</code> adds an additional context, HTML. In
  600. this context, it sets the suffix to 'ajax.phtml' in order to
  601. differentiate the context from a normal request. No additional
  602. headers are returned.
  603. </para>
  604. <example id="zend.controller.actionhelpers.contextswitch.ajaxcontext.example">
  605. <title>Allowing Actions to Respond To Ajax Requests</title>
  606. <para>
  607. In this following example, we're allowing requests to the
  608. actions 'view', 'form', and 'process' to respond to AJAX
  609. requests. In the first two cases, 'view' and 'form', we'll
  610. return HTML snippets with which to update the page; in the
  611. latter, we'll return JSON.
  612. </para>
  613. <programlisting role="php"><![CDATA[
  614. class CommentController extends Zend_Controller_Action
  615. {
  616. public function init()
  617. {
  618. $ajaxContext = $this->_helper->getHelper('AjaxContext');
  619. $ajaxContext->addActionContext('view', 'html')
  620. ->addActionContext('form', 'html')
  621. ->addActionContext('process', 'json')
  622. ->initContext();
  623. }
  624. public function viewAction()
  625. {
  626. // Pull a single comment to view.
  627. // When AjaxContext detected, uses the comment/view.ajax.phtml
  628. // view script.
  629. }
  630. public function formAction()
  631. {
  632. // Render the "add new comment" form.
  633. // When AjaxContext detected, uses the comment/form.ajax.phtml
  634. // view script.
  635. }
  636. public function processAction()
  637. {
  638. // Process a new comment
  639. // Return the results as JSON; simply assign the results as
  640. // view variables, and JSON will be returned.
  641. }
  642. }
  643. ]]></programlisting>
  644. <para>
  645. On the client end, your AJAX library will simply request the
  646. endpoints '/comment/view', '/comment/form', and
  647. '/comment/process', and pass the 'format' parameter:
  648. '/comment/view/format/html', '/comment/form/format/html',
  649. '/comment/process/format/json'. (Or you can pass the parameter
  650. via query string: e.g., "?format=json".)
  651. </para>
  652. <para>
  653. Assuming your library passes the 'X-Requested-With:
  654. XmlHttpRequest' header, these actions will then return the
  655. appropriate response format.
  656. </para>
  657. </example>
  658. </sect4>
  659. </sect3>
  660. <!--
  661. vim:se ts=4 sw=4 et:
  662. -->