AJAX Pattern: Custom Message


 definition
 overview
 ajax pattern in action
 source code



definition

Messages between browser and server contain custom formatted data.

Frequency of use:   medium

overview

Sometimes you deal with legacy data sources (e.g. 80 column data cards) or data that is complex and has unusual data relations. In situations like these it may be best to implement your own custom data format.

AJAX is flexible and the message payload can take any arbitrary form as long as the client and server understand each other, that is, the 'packing' on one side must match the 'unpacking' on the other side.

ajax pattern in action

This example retrieves US census data from a database. It displays a list of states on the left and census details for the selected state on the right.

When a user selects a different state, the browser uses AJAX to retrieve census details for that state. The custom message uses a vertical bar ('|') to separate the different data items. The browser uses the Javscript split() function to break the data into its constituent parts.


Example: US Census Data by State

State Population


    Population in 2000:
    

    Population in 2004:
    

    Population in 2005:
    

    Area (sq. miles):
    

    Population Density:
    



source code

    Click here to view the source code.