AJAX Support

All modern frameworks have some support for AJAX - the asynchronous javascript XML request method - basically loading more data into a page without triggering a page re-load or having to visit another page. There are many examples now, Gmail probably the best known.

Scorpio can also handle AJAX requests.

AJAX support can be added extremely easily in a Scorpio web app. In fact it is almost trivial. Simply create a template (either xml or json or js or fragment) and in your Javascript library call the URI with /as.TYPE and the output will now be in a format suitable for AJAX. XML is recommended as it fits better with the template nature of Scorpio and encoding suitable JSON responses can be awkward.

This works best for searches or lists or code fragments (e.g. a news pop-up). You may find you have to make minor changes to have it work exactly how you want, but that is the basics.

The mvcRequest offers an isAjaxRequest method for detecting if the request was made with an AJAX header or with the parameter ajax=1 (or true).

You can use any javascript library you like with Scorpio - the project does not have a preference - so you can use which ever best suites your needs.

Pre Scorpio 0.3 

In previous versions of Scorpio two ajax systems were present in the base distribution: Prototype JS and xajax. Prototype JS is the well known Ruby on Rails default javascript framework and xajax is a PHP ajax implementation. From Scorpio v0.3 onwards both are deprecated and Prototype has been removed. xajax remains but will be removed in a later version.

xajax is still available but has been moved away from the mvcControllerBase into a dedicated controller mvcXajaxController. This extends mvcController - your site specific controller and adds in the xajax methods.

You will need to add ajax routing to your controller by setting the "ajaxserver" as a valid route on the controller and then intercepting and redirecting these requests to xajax.

Similarly you will need to ensure that the xajax javascript is injected into the view templates.

It should be noted that xajax is not the recommended method for implementing ajax into a site. It is a much better idea to use a javascript framework instead.

 

<  1  >