and JSON with jQuery

Chen-Hsiang (Jones) Yu [email protected]

httppy://chyu.scri pts.mit.edu/a jax-json-jquer y-examppples.zip

Jan. 5, 2010 6.470 1 The goal of this lecture

• Understand and know how to use AJAX • Understand JSON • Understand and know how to use jQuery • Understand the usage of AJAX and JSON with jQuer y

jQuery JSON AJAX

Jan. 5, 2010 6.470 2 Outline

•AJAX • JSON •jQuery

Jan. 5, 2010 6.470 3 Prerequisites

• MIT SIPB Web Script Service ƒ http://scripts.mit .edu/web/ ƒ Instructions: o Using any terminal to connect to Athena o athena% add scripts athena% signup-web o Your web space will be at http://username.scripts.mit.edu/ o You can use any FTP client to upload your files and scripts

• FTP client: ƒ Filezilla (Windows/Linux/Mac) o http://filezilla-project.org/download.php ƒ Alternative: OpenAFS - http://www.openafs.org/

Jan. 5, 2010 6.470 4 AJAX

Jan. 5, 2010 6.470 5 AJAX - 1

• It stands for “Asynchronous JavaScript and XML”

• It was first mentioned by Jesse James Garrett in 2005. [1]

• It is not a new technology. It is several technologies. [1]

ƒ standards-based presentation: XHTML and CSS

ƒ dynamic display and interaction: DOM

ƒ data interchange and manipulation: XML and XSLT

ƒ asynchronous data retrieval: XMLHttpRequest

ƒ binding everything together: JavaScript

Jan. 5, 2010 6.470 6 AJAX - 2

: Static web site vs. AJAX site

• AJAX engine: XMLHttpRequest object

ƒ It allows for asynchronous communication

ƒ Instead of freezing up until the completeness, the browser can communicate with server and continue as normal.

Jan. 5, 2010 6.470 7 AJAX - 3

Figure: Traditional model vs. AJAX model [1] Figure: Synchronous interaction vs. Asynchronous interaction [1] Jan. 5, 2010 6.470 8 AJAX - 4

a. abandon b. v./n. . to give up completely abash v. to make embarrassed SQL Query

Web Browser

data Database 1. mySQL Script Languages 1. PHP

CttContent: 1. HTML Document 2. XML Document 3. JSON Document Figure: The process of AJAX call

Jan. 5, 2010 6.470 9 AJAX - 5

• POST and GET calls in AJAX [2]

ƒ GET places arguments in the query string, but POST doesn’t.

ƒ No noticeable difference in AJAX - AJAX request does not appear in the address bar.

ƒ GET call in AJAX still has the size limitation on the amount of data that can be passed.

ƒ General principle:

o GET method: it is used to retrieve data to display in the page and the data is not expected to be changed on the server.

o POST method: it is used to update information on the server.

Jan. 5, 2010 6.470 10 Exercise: Example 1

letters

A abandon B v./n. content C to give up completely abash v. to make embarrassed

… letter …

GRE Word List

Jan. 5, 2010 6.470 11

ABANDON

vv/n./n.
to give up completely