AJAX Pattern: Custom Message
 |
Messages between browser and server contain custom formatted data.
Frequency of use:
medium
|
|
 |
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.
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
Click here to view the source code.