computer science s-75

13
0 Computer Science S-75 Building Dynamic Websites Harvard Summer School https://www.cs75.net/ Lecture 7: Ajax David J. Malan [email protected]

Upload: others

Post on 16-Oct-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Science S-75

0

Computer Science S-75 Building Dynamic Websites Harvard Summer School

https://www.cs75.net/

Lecture 7: Ajax

David J. Malan

[email protected]

Page 2: Computer Science S-75

1

DOM <!DOCTYPE html> <html> <head> <title>My title</title> </head> <body> <a href="">My link</a> <h1>My header</h1> </html>

Page 3: Computer Science S-75

2

DOM <!DOCTYPE html> <html> <head> <title>My title</title> </head> <body> <a href="">My link</a> <h1>My header</h1> </html>

Image from http://www.w3schools.com/htmldom/.

Page 4: Computer Science S-75

3

Ajax

source unknown

Page 5: Computer Science S-75

4

XMLHttpRequest   abort()   getAllResponseHeaders()   getResponseHeader(header)   open(method, url)   open(method, url, async)   open(method, url, async, user)   open(method, url, async, user, password)   send()   send(data)   setRequestHeader(header, value)

Page 6: Computer Science S-75

5

XMLHttpRequest   onreadystatechange   readyState

  0 (unitialized)   1 (open)   2 (sent)   3 (receiving)   4 (loaded)

  responseBody   responseText   responseXML   status

  200 (OK)   404 (Not Found)   500 (Internal Server Error)   . . .

  statusText

Page 7: Computer Science S-75

6

Content Types   HTML (text/html)   XML (text/xml)   JSON (application/json)

Page 8: Computer Science S-75

7

JSON

Table from http://www.json.org/.

Page 9: Computer Science S-75

8

PHP + JSON   json_encode($value)

http://us3.php.net/manual/en/function.json-encode.php   eval(string)

http://www.json.org/js.html

Page 10: Computer Science S-75

9

Progress...   Ajax loading gif generator

http://www.ajaxload.info/   AJAX Activity indicators

http://mentalized.net/activity-indicators/   . . .

Page 11: Computer Science S-75

10

jQuery.ajax()

http://api.jquery.com/jQuery.ajax/

Page 12: Computer Science S-75

11

bart.gov

Page 13: Computer Science S-75

12

Computer Science S-75 Building Dynamic Websites Harvard Summer School

https://www.cs75.net/

Lecture 7: Ajax

David J. Malan

[email protected]