Web 2.0, Ajax, Dynamic Sites

April 2, 2008

Harvard University
Division of Continuing Education
Extension School

Course Web Site: http://cscie12.dce.harvard.edu/

Copyright 1998-2008 David P. Heitmeyer

Instructor email: david_heitmeyer@harvard.edu
Course staff email: cscie12@fas.harvard.edu

Web 2.0

Suggested readings for Web 2.0:

What is Web 2.0?

Web 2.0 Features and Characteristics

What Is Web 2.0: Design Patterns and Business Models for the Next Generation of Software by Tim O'Reilly

Principles, Characteristics, Features:

Web 1.0 and 2.0 Examples

Web 2.0 in Images

Web 2.0 Meme Map by Tim O'Reilly
web20mememap


Visualizing Web 2.0 by Dion Hinchcliffe
web2.0


Visualizing Web 2.0, Peter, blog.forret.com
Web 2.0 Overview

Web 2.0 Examples

Zillow
zillow
www.zillow.com

Housingmaps.com
housing maps
www.housingmaps.com

ChicagoCrime.org
chicagocrime.org
www.chicagocrime.org

Del.icio.us
del.icio.us
del.icio.us

Flickr
flickr
flickr.com

Encyclopedia of Life

Encyclopedia of Life, www.eol.org

WASHINGTON (May 9, 2007) – Many of the world’s leading scientific institutions today announced the launch of the Encyclopedia of Life, an unprecedented global effort to document all 1.8 million named species of animals, plants, and other forms of life on Earth. For the first time in the history of the planet, scientists, students, and citizens will have multi-media access to all known living species, even those that have just been discovered.
more

Falco peregrinus (Peregrine Falcon)

eol

eol

eol

Google News

google news

Amazon Web Services

Amazon.com offers several different web services, including one for e-commerce.

Amazon Book Information

http://www.amazon.com/gp/product/006251587X%3ftag=webservices-20%26link_code=xm2%26camp=2025%26dev-t=DEVELOPER_TOKEN

Amazon WS

Yahoo! Developer Network

Yahoo! Developer Network. REST Web Services using XML and JSON.

Rich Internet Applications

Rich Internet Applications (RIA)
Rich User Experience

gmail
gmail.com


google maps
maps.google.com


google calendar
calendar.google.com


google documents
docs.google.com

XHR, Ajax, AHAH

AJAX: A New Approach to Web Applications, from Adaptive Path. by Jesse James Garrett

ajax

Ajax Flow

ajax schematic

Ajax Overview


Technologies Involved

Course Search with Ajax and jQuery

http://minerva.dce.harvard.edu/ajax/course_jquery.html

ajax

There is a URL that returns a list of courses given a course group (as an XHTML snippet):

Note that the search is case-insensitive.

What's involved:

Import jQuery

jQuery function:

Form:

Conferences: Loading with HTML

Example

conferencse

Markup:

JS:

Conferences: JSON

Example

Instead of returning HTML to be put into the page, our server-side process will return JSON (JavaScript Object Notation). We can then process the JSON data into the page.

JSON data example:

And the JS to process it:

conferences

Conferences: XML

Example

Return XML data:
xml data

And the JS changes slightly to process XML instead of JSON:

conferences xml

Mutliple Filter Criteria with Ajax

We create an interface that allows schools to be filtered by

Pulldown menus created through jQuery and Ajax.

When a criteria is selected, we use Ajax to dynamically update the pulldown options as well as the table of results.

conferences

conferences

conferences

Data from a Third Party

You may wish to use data from third parties. You may wish to provide your data to others to use. This is where XML and JSON are extremely useful.

Yahoo! Web Services

Yahoo! News Search provides search results in XML and JSON formats.

Security restrictions put limitations on cross-domain JSON requests.


yahoo news yahoo news

JS

Markup

Working Example: Yahoo News and JSON

Google Maps: Ivy Group

Javascript Application that uses Ajax to pull in map marker data.

Place "markers" and information on maps via XML data.

Live Example: Ivy Group Map
Ivy Group map

Markup:

Data (ivy.xml)

JS to process Data

Google Maps: CSCI E-12

Javascript Application that uses Ajax to pull in map marker data.

Place "markers" and information on maps via XML data.

CSCI E-12 Campus Map
campus map

Markup:

Marker Data

campus_data_spring2008.xml
campus_data.xml

Javascript createMarker function:

JavaScript Applications

The SIMILE project from MIT has some great examples of JS applications

US Congress and Exhibit

Provide the data and the template, and Exhibit provides the functionality: different views, timeline according to birth date, filtering, sorting, and grouping.

Tiles View
Exhibit and Congress

Table View (columns are sortable)
Exhibit and Congress

Thumbnails View (Filters applied: California, Democrat)
Exhibit and Congress

Timeline View
Visible are those with birthdays in 1969-1972. Timeline is scrollable.
Exhibit and Congress

Congress data used with permission from GovTrack.US.

Dynamically Created Documents

Note that can content is typically XHTML, but could be any type of media (e.g. CSS, PDF, PNG, JPG, GIF, Excel, Word, etc.)

Things to consider...

There's no single best way to produce dynamic documents, but depending upon the situation, some solutions will be better than others.

Web Development Languages & Frameworks

Server-side Architecture

HTTP Client and Server

client and server and HTTP

CGI Process

Examples: CGI

HTTP client and server and CGI process

External Process

Examples: FastCGI (language neutral), Servlet/JSP, ColdFusion

HTTP server and external process

Internal

Examples: PHP, Perl under Apache mod_perl, Servlet/JSP, ColdFusion

HTTP server and internal process

Development Structure

"XHTML within a Program" Examples

Markup or content is embedded within a program.

first.cgi

first.cgi

second.cgi

second.cgi

Here the "CGI.pm" Perl module creates tags with subroutine calls.

second.cgi

CGI Examples: third.cgi

CGI Examples: fourth.cgi

Without a "name", present the user a form. With a name, provide a greeting.

Simple Servlet Example

"XHTML with Programs" Examples

Examples include: SSI, PHP, JSP, ASP, some Perl template systems

JSP example:

jsp example

PHP: Hypertext Processor

From the PHP manual:

PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Its syntax draws upon C, Java, and Perl, and is easy to learn. The main goal of the language is to allow web developers to write dynamically generated web pages quickly, but you can do much more with PHP.

Example

http://cscie12.dce.harvard.edu/cgi/hello.php

Model, View, Controller (MVC) Design Pattern

MVC

MVC design pattern separates:


You can adopt this design pattern regardless of language or server-architecture (CGI, internal process, external process). Some frameworks make using MVC possible, some hard, some easy, some insist on it.

Java Expression Language (EL)

e.g.ivy/list.html

Template uses an "expression" language to produce content, not Java. There is a Java process ("Controller" and "Model") that gets the data, and then forwards the data to the "View" component for processing on the server before it is sent to the browser.

In this example, an array of "schools" is available to the view. The schools are essentially a map that could be represented like:

Sample Data from "Model"

EL Page ("View")

The result:
jexl

Producing a Different View

e.g.ivy/seals.html

Based upon the URL pattern, the "Controller" can call a different view. The "Model" provides the same data in this case. Our template produces a display of the schools' seals.

The result:
jexl

EL to Produce Data for Google Maps

e.g.ivy/markers.xml

Here we use a different template to produce "marker" data for Google Maps. Note that the data sent is the same ("Model" is doing the same thing). The "Controller" would be calling a different view based upon a URL pattern.

The result:
jexl

Template Toolkit (Perl and Python)

Template Toolkit

The Template Toolkit is a fast, powerful and easily extensible template processing system.


  1. HTTP Request is made
  2. Data is retrieved
  3. Data given to Toolkit Template template for processing

Template Toolkit Example

template toolkit and funding

Data for our Dynamic Site

Conferences

list.cgi

screenshot

The template that will display the data.

Getting the Data: CGI

list.cgi

Wrapping the Template

Where did everything else come from? The files that our part of out Template Toolkit site are:

site/wrapper

site/html

site/layout

Conferences

Alter the CGI so that it takes a template argument from PATH_INFO:

http://cscie12.dce.harvard.edu/cgi/conferences/list.cgi/conferences

And now, let's list the schools:

screenshot

Conferences [fun]

Alter the CGI so that it takes a template argument from PATH_INFO:

http://cscie12.dce.harvard.edu/cgi/conferences/list.cgi/schools_thumbshots

screenshot

The [% INCLUDE site/thumbshots %] includes the file root/lib/site/thumbshots

screenshot

Template Toolkit Build

Building a static site with Template Toolkit.

pinocchios pizza

The templates (*.html) files in the "src" directory will be processed and new files will be created in the "html" directory.

Directory and file structure:

TT 'ttree'

ttree is the program that will recursively go through a directory and process templates. The resulting content is saved to a file in another directory.

And now look in the "html" directory:

Template Toolkit: Datafiles

Can process data as well.

Pinocchio's Menu

Menu data is:

And the menu.html template is:

PHP Example

courses

courses

FAS Course Data

Course data for Faculty of Arts & Sciences is in a mysql database on minerva (username: class; database name: coursecatalog)

Mixing of Concerns instead of SOC

Mixing of concerns instead of SOC. This particular example is with PHP, but you can easily achieve "entangling of concerns" with Java (JSP), ASP, Python, or Perl. The problem is not with the language, but with the structure.

departments.php

courses.php

PHP Smarty Templates

smarty

The template (departments.tpl):

Get the departments: smarty-dept.php

Smarty Template for Courses

smarty

The template (courses.tpl):

Get the Courses for the CHEM department: smarty-courses.php?department_code=CHEM