SlideShare a Scribd company logo
JavaScript, AJAX, jQuery, Code, OH MY! Or: How cool web stuff works
The Web That Was Web Page Web Page CGI
No reloading  OMG LMAO!
 
<! DOCTYPE  html PUBLIC  &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot; > < html xmlns = &quot;http://www.w3.org/1999/xhtml&quot; > < head > < meta http-equiv = &quot;Content-Type&quot;  content = &quot;text/html; charset=ISO-8859-1&quot;  /> < title >I'm a web page</ title > </ head > < body > < div id = &quot;top&quot; >This is the top.</ div > </ body > </ html >
The Document Object Model (DOM) XML Document Object Model
JavaScript! Magic?
Referencing an XHTML element < div  id = &quot;top&quot; >This is the top.</ div > … reference the element by unique ID document. getElementById( &quot;top&quot; ) … this returns the selected element in the parse tree. DOM Element Properties
How to Lose Friends <! DOCTYPE  html PUBLIC  &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot; > < html xmlns = &quot;http://www.w3.org/1999/xhtml&quot; > < head > < meta http-equiv = &quot;Content-Type&quot;  content = &quot;text/html; charset=ISO-8859-1&quot;  /> < title >I'm a web page</ title > < script type= &quot;text/javascript&quot;> function  element() {   alert( document. getElementById( &quot;top&quot;).innerHTML); } </ script> </ head > < body onload = &quot;element()&quot; > < div id = &quot;top&quot; >This is the top.</ div > </ body > </ html >
Manipulating Element Contents InnerHTML! DOM Manipulation!
Events <! DOCTYPE  html PUBLIC  &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot; > < html xmlns = &quot;http://www.w3.org/1999/xhtml&quot; > < head > < meta http-equiv = &quot;Content-Type&quot;  content = &quot;text/html; charset=ISO-8859-1&quot;  /> < title >I'm also a web page</ title > < script type= &quot;text/javascript&quot;> function  update() {   document. getElementById( &quot;contents&quot;).innerHTML  =  &quot;You clicked!&quot;; } </ script> </ head > < body > < div id = &quot;contents&quot; >I'm here when you initially load.</ div > < input type = &quot;button&quot;  value = &quot;Click Me&quot;  onclick = &quot;update()&quot;  /> </ body > </ html > Try Me
Complicated Behavior… Path101
XMLHttpRequest() XMLHttpRequest (XHR) transfers data between a client (browser) and a server over background HTTP requests.
Using XMLHttpRequest …in a cross-browser friendly way var request  =  new  XMLHttpRequest(); request. open( &quot;GET&quot;, url,  false); request. send( null); if(!request. getResponseHeader( &quot;Date&quot;)) {   var cached  = request;   request =  new  XMLHttpRequest();   var ifModifiedSince  = cached. getResponseHeader( &quot;Last-Modified&quot;);   ifModifiedSince  = (ifModifiedSince) ?   ifModifiedSince : new  Date( 0);  // January 1, 1970   request. open( &quot;GET&quot;, url,  false);   request. setRequestHeader( &quot;If-Modified-Since&quot;, ifModifiedSince);   request. send( &quot;&quot;);   if(request. status  ==  304) {   request  = cached;   } }
JavaScript Libraries A good library will abstract away the ugly details of cross-platform code. Prototype (the first major lib) jQuery (write less, do more) Script.aculo.us (the prettiest) YUL! (the yahoo!iest) Etc…
jQuery < html >   < head >   < script type= &quot;text/javascript&quot;  src= &quot;jquery.js&quot;></ script>   <script type= &quot;text/javascript&quot;>   // Your code goes here   </ script>   </ head >   < body >   < a href = &quot;http://jquery.com/&quot; >jQuery</ a >   </ body > </ html >
jQuery Selector Syntax $(‘#elementid’) $(‘.classname’) $(‘#content a.link’)
Events $(‘#top’).click(); $(‘#top’).click(function() { // do stuff when #top is clicked });
Document Ready Not “onload”! $(document).ready(function(){ // Your code here });
Local Example < html >   < head >   < script type= &quot;text/javascript&quot;  src= &quot;http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js&quot;></ script>   <script type= &quot;text/javascript&quot;>   $( document).ready( function() {   $( &quot;#content&quot;). click( function() {   alert( &quot;hi&quot;);   });   });   </ script>   </ head >   < body >   < div id = &quot;content&quot; >Did anyone go to Denny's today?</ div >   </ body > </ html >
… explore… Thank you!
Ad

Recommended

Javascript
Javascript
padmaashree Arunachalem
 
Anvita Dynamic Fontson Web Feb2001
Anvita Dynamic Fontson Web Feb2001
guest6e7a1b1
 
Javascript Basic
Javascript Basic
Kang-min Liu
 
WCF & JQuery
WCF & JQuery
Chris Love
 
YL Intro html
YL Intro html
dilom1986
 
1.1 xhtml basics
1.1 xhtml basics
Bulldogs83
 
Basic HTML
Basic HTML
coachhahn
 
HTML presentation for beginners
HTML presentation for beginners
jeroenvdmeer
 
We9 Struts 2.0
We9 Struts 2.0
wangjiaz
 
Intro to Html 5
Intro to Html 5
Shauvik Roy Choudhary, Ph.D.
 
Html5 structure tags
Html5 structure tags
SEO SKills
 
Findability Bliss Through Web Standards
Findability Bliss Through Web Standards
Aarron Walter
 
Learning HTML
Learning HTML
Desarae Veit
 
Microformats HTML to API
Microformats HTML to API
elliando dias
 
#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]
Dalibor Gogic
 
Html5
Html5
dotNETUserGroupDnipro
 
Jade & Javascript templating
Jade & Javascript templating
wearefractal
 
Html basics IML 140 (weeks 2-3)
Html basics IML 140 (weeks 2-3)
Evan Hughes
 
Lecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITP
yucefmerhi
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
BG Java EE Course
 
Microsoft and jQuery
Microsoft and jQuery
Eric ShangKuan
 
The Basics of (X)HTML Tags
The Basics of (X)HTML Tags
LearningNerd
 
Ajax ons2
Ajax ons2
Chad Davis
 
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Sergey Ilinsky
 
Html
Html
Chidanand Byahatti
 
HTML all tags .........its to much helpful for beginners
HTML all tags .........its to much helpful for beginners
Nimrakhan89
 
Java Script
Java Script
siddaram
 
Developing Gadgets
Developing Gadgets
Quirk
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7
phuphax
 
Developing and testing ajax components
Developing and testing ajax components
Ignacio Coloma
 

More Related Content

What's hot (18)

We9 Struts 2.0
We9 Struts 2.0
wangjiaz
 
Intro to Html 5
Intro to Html 5
Shauvik Roy Choudhary, Ph.D.
 
Html5 structure tags
Html5 structure tags
SEO SKills
 
Findability Bliss Through Web Standards
Findability Bliss Through Web Standards
Aarron Walter
 
Learning HTML
Learning HTML
Desarae Veit
 
Microformats HTML to API
Microformats HTML to API
elliando dias
 
#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]
Dalibor Gogic
 
Html5
Html5
dotNETUserGroupDnipro
 
Jade & Javascript templating
Jade & Javascript templating
wearefractal
 
Html basics IML 140 (weeks 2-3)
Html basics IML 140 (weeks 2-3)
Evan Hughes
 
Lecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITP
yucefmerhi
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
BG Java EE Course
 
Microsoft and jQuery
Microsoft and jQuery
Eric ShangKuan
 
The Basics of (X)HTML Tags
The Basics of (X)HTML Tags
LearningNerd
 
Ajax ons2
Ajax ons2
Chad Davis
 
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Sergey Ilinsky
 
Html
Html
Chidanand Byahatti
 
HTML all tags .........its to much helpful for beginners
HTML all tags .........its to much helpful for beginners
Nimrakhan89
 
We9 Struts 2.0
We9 Struts 2.0
wangjiaz
 
Html5 structure tags
Html5 structure tags
SEO SKills
 
Findability Bliss Through Web Standards
Findability Bliss Through Web Standards
Aarron Walter
 
Microformats HTML to API
Microformats HTML to API
elliando dias
 
#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]
Dalibor Gogic
 
Jade & Javascript templating
Jade & Javascript templating
wearefractal
 
Html basics IML 140 (weeks 2-3)
Html basics IML 140 (weeks 2-3)
Evan Hughes
 
Lecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITP
yucefmerhi
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
BG Java EE Course
 
The Basics of (X)HTML Tags
The Basics of (X)HTML Tags
LearningNerd
 
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Sergey Ilinsky
 
HTML all tags .........its to much helpful for beginners
HTML all tags .........its to much helpful for beginners
Nimrakhan89
 

Similar to JWU Guest Talk: JavaScript and AJAX (20)

Java Script
Java Script
siddaram
 
Developing Gadgets
Developing Gadgets
Quirk
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7
phuphax
 
Developing and testing ajax components
Developing and testing ajax components
Ignacio Coloma
 
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Richard Davis
 
Randy Witt Audio Assignment
Randy Witt Audio Assignment
PAVenturer
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
borkweb
 
Html ppt
Html ppt
Iblesoft
 
HTML5 - techMaine Presentation 5/18/09
HTML5 - techMaine Presentation 5/18/09
pemaquid
 
Ajaxppt
Ajaxppt
vsnmurthy
 
Ajaxppt
Ajaxppt
Ratna Prashanth
 
Lecture1 B Frames&Forms
Lecture1 B Frames&Forms
Sur College of Applied Sciences
 
HTML Fundamentals
HTML Fundamentals
Doncho Minkov
 
Introducing YUI
Introducing YUI
Christian Heilmann
 
Understanding html
Understanding html
Ray Villalobos
 
PHPTAL introduction
PHPTAL introduction
'"">
 
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Alfresco Software
 
JSP Custom Tags
JSP Custom Tags
BG Java EE Course
 
Html for translators
Html for translators
Andrea Spila
 
GTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementation
David Calavera
 
Java Script
Java Script
siddaram
 
Developing Gadgets
Developing Gadgets
Quirk
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7
phuphax
 
Developing and testing ajax components
Developing and testing ajax components
Ignacio Coloma
 
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Richard Davis
 
Randy Witt Audio Assignment
Randy Witt Audio Assignment
PAVenturer
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
borkweb
 
HTML5 - techMaine Presentation 5/18/09
HTML5 - techMaine Presentation 5/18/09
pemaquid
 
PHPTAL introduction
PHPTAL introduction
'"">
 
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Alfresco Software
 
Html for translators
Html for translators
Andrea Spila
 
GTAC: AtomPub, testing your server implementation
GTAC: AtomPub, testing your server implementation
David Calavera
 
Ad

More from Hilary Mason (12)

Grace Hopper Conference Opening Keynote
Grace Hopper Conference Opening Keynote
Hilary Mason
 
Short URLs, Big Fun
Short URLs, Big Fun
Hilary Mason
 
Strata NY Sep 2011: Big Data, Short URLs: Learning in Realtime
Strata NY Sep 2011: Big Data, Short URLs: Learning in Realtime
Hilary Mason
 
PyCon 2011 Keynote
PyCon 2011 Keynote
Hilary Mason
 
Machine Learning for Web Data
Machine Learning for Web Data
Hilary Mason
 
A Data-driven Look at the Realtime Web
A Data-driven Look at the Realtime Web
Hilary Mason
 
IgniteNYC: How to Replace Yourself With a Very Small Shell Script
IgniteNYC: How to Replace Yourself With a Very Small Shell Script
Hilary Mason
 
Practical Data Analysis in Python
Practical Data Analysis in Python
Hilary Mason
 
Have data? What now?!
Have data? What now?!
Hilary Mason
 
Analytics for Virtual Worlds
Analytics for Virtual Worlds
Hilary Mason
 
Experiential Learning in Second Life
Experiential Learning in Second Life
Hilary Mason
 
Virtual Worlds in Education
Virtual Worlds in Education
Hilary Mason
 
Grace Hopper Conference Opening Keynote
Grace Hopper Conference Opening Keynote
Hilary Mason
 
Short URLs, Big Fun
Short URLs, Big Fun
Hilary Mason
 
Strata NY Sep 2011: Big Data, Short URLs: Learning in Realtime
Strata NY Sep 2011: Big Data, Short URLs: Learning in Realtime
Hilary Mason
 
PyCon 2011 Keynote
PyCon 2011 Keynote
Hilary Mason
 
Machine Learning for Web Data
Machine Learning for Web Data
Hilary Mason
 
A Data-driven Look at the Realtime Web
A Data-driven Look at the Realtime Web
Hilary Mason
 
IgniteNYC: How to Replace Yourself With a Very Small Shell Script
IgniteNYC: How to Replace Yourself With a Very Small Shell Script
Hilary Mason
 
Practical Data Analysis in Python
Practical Data Analysis in Python
Hilary Mason
 
Have data? What now?!
Have data? What now?!
Hilary Mason
 
Analytics for Virtual Worlds
Analytics for Virtual Worlds
Hilary Mason
 
Experiential Learning in Second Life
Experiential Learning in Second Life
Hilary Mason
 
Virtual Worlds in Education
Virtual Worlds in Education
Hilary Mason
 
Ad

Recently uploaded (20)

You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 

JWU Guest Talk: JavaScript and AJAX

  • 1. JavaScript, AJAX, jQuery, Code, OH MY! Or: How cool web stuff works
  • 2. The Web That Was Web Page Web Page CGI
  • 3. No reloading OMG LMAO!
  • 4.  
  • 5. <! DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot; > < html xmlns = &quot;http://www.w3.org/1999/xhtml&quot; > < head > < meta http-equiv = &quot;Content-Type&quot; content = &quot;text/html; charset=ISO-8859-1&quot; /> < title >I'm a web page</ title > </ head > < body > < div id = &quot;top&quot; >This is the top.</ div > </ body > </ html >
  • 6. The Document Object Model (DOM) XML Document Object Model
  • 8. Referencing an XHTML element < div id = &quot;top&quot; >This is the top.</ div > … reference the element by unique ID document. getElementById( &quot;top&quot; ) … this returns the selected element in the parse tree. DOM Element Properties
  • 9. How to Lose Friends <! DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot; > < html xmlns = &quot;http://www.w3.org/1999/xhtml&quot; > < head > < meta http-equiv = &quot;Content-Type&quot; content = &quot;text/html; charset=ISO-8859-1&quot; /> < title >I'm a web page</ title > < script type= &quot;text/javascript&quot;> function element() { alert( document. getElementById( &quot;top&quot;).innerHTML); } </ script> </ head > < body onload = &quot;element()&quot; > < div id = &quot;top&quot; >This is the top.</ div > </ body > </ html >
  • 10. Manipulating Element Contents InnerHTML! DOM Manipulation!
  • 11. Events <! DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot; > < html xmlns = &quot;http://www.w3.org/1999/xhtml&quot; > < head > < meta http-equiv = &quot;Content-Type&quot; content = &quot;text/html; charset=ISO-8859-1&quot; /> < title >I'm also a web page</ title > < script type= &quot;text/javascript&quot;> function update() { document. getElementById( &quot;contents&quot;).innerHTML = &quot;You clicked!&quot;; } </ script> </ head > < body > < div id = &quot;contents&quot; >I'm here when you initially load.</ div > < input type = &quot;button&quot; value = &quot;Click Me&quot; onclick = &quot;update()&quot; /> </ body > </ html > Try Me
  • 13. XMLHttpRequest() XMLHttpRequest (XHR) transfers data between a client (browser) and a server over background HTTP requests.
  • 14. Using XMLHttpRequest …in a cross-browser friendly way var request = new XMLHttpRequest(); request. open( &quot;GET&quot;, url, false); request. send( null); if(!request. getResponseHeader( &quot;Date&quot;)) { var cached = request; request = new XMLHttpRequest(); var ifModifiedSince = cached. getResponseHeader( &quot;Last-Modified&quot;); ifModifiedSince = (ifModifiedSince) ? ifModifiedSince : new Date( 0); // January 1, 1970 request. open( &quot;GET&quot;, url, false); request. setRequestHeader( &quot;If-Modified-Since&quot;, ifModifiedSince); request. send( &quot;&quot;); if(request. status == 304) { request = cached; } }
  • 15. JavaScript Libraries A good library will abstract away the ugly details of cross-platform code. Prototype (the first major lib) jQuery (write less, do more) Script.aculo.us (the prettiest) YUL! (the yahoo!iest) Etc…
  • 16. jQuery < html > < head > < script type= &quot;text/javascript&quot; src= &quot;jquery.js&quot;></ script> <script type= &quot;text/javascript&quot;> // Your code goes here </ script> </ head > < body > < a href = &quot;http://jquery.com/&quot; >jQuery</ a > </ body > </ html >
  • 17. jQuery Selector Syntax $(‘#elementid’) $(‘.classname’) $(‘#content a.link’)
  • 18. Events $(‘#top’).click(); $(‘#top’).click(function() { // do stuff when #top is clicked });
  • 19. Document Ready Not “onload”! $(document).ready(function(){ // Your code here });
  • 20. Local Example < html > < head > < script type= &quot;text/javascript&quot; src= &quot;http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js&quot;></ script> <script type= &quot;text/javascript&quot;> $( document).ready( function() { $( &quot;#content&quot;). click( function() { alert( &quot;hi&quot;); }); }); </ script> </ head > < body > < div id = &quot;content&quot; >Did anyone go to Denny's today?</ div > </ body > </ html >