AJAX Pattern: Javascript Message


 definition
 overview
 ajax pattern in action
 source code



definition

Messages from the server to the client contain Javascript. The Javascript is dynamically executed by the browser.

Frequency of use:   low

overview

In this pattern a JavaScript message is sent from the server to the browser where the code executes. The message is a simple text string that contains JavaScript code. The string can be long and may contain complex logic.

This approach relies on Javascript's eval() function which dynamically evaluates a string and executes it as Javascript code. All valid Javascript works, including code that makes calls into the Microsoft AJAX library.

ajax pattern in action

In this simple example the user is asked to file an insurance claim online. The categories are: Life, Health, Car, and Home insurance. Each category has its own specific set of questions that are assigned dynamically by Javascript code that is returned from the server and eval'd on the client.



Example: Insurance Claim Questionnaire

    Select type of Insurance and answer the brief questionnaire.

Type of Insurance:  
 Question4
 Question4
 Question4
 Question4
 Question4
  
 

source code

    Click here to view the source code.