examples:example3

This is an old revision of the document!


Giving Life to Javascript Values

In Facebook, user pages are updated with the last messages from friends without the need to reload the page. To achieve this, Facebook uses Ajax: a set of Web development techniques for asynchronous client-to-server communication. However, when page elements (e.g. the last messages) depend on Ajax responses, they must be updated after every communication with the server to show up-to-date information. The complexity of Ajax updates can be alleviated by introducing basic support for reactive values: when a value originating from an Ajax response changes, all page elements depending on it are updated accordingly. Using AspectScript, we introduce a library for basic reactive values.

Toggle between the code and example


In the previous window, the number of messages are updated every 3 seconds. The piece of code necessary to achieve is the following:

var msgs = new ReactiveValue( "lastMsgs.php? id =..." , 3000);
newMessages.innerHTML = msgs;
  • examples/example3.1257539460.txt.gz
  • Last modified: 2009/11/06 16:31
  • by aspectscript