SlideShare a Scribd company logo
Sponsored by Upsilon Pi Epsilon The Computer Science Honors Society XML and AJAX
XML : Basics XML stands for E X tensible  M arkup  L anguage  XML is a  markup language  much like HTML  XML was designed to  describe data   XML tags are not predefined. You must  define your own tags   XML should use a  Document Type Definition  (DTD) or an  XML Schema  to describe the data  XML is a W3C Recommendation  HTML is about displaying information, while XML is about describing information.  XML doesn’t do anything itself-  You do something with it. Source:  http://www.w3schools.com/xml/xml_whatis.asp
XML : Syntax & Example Tags open and close with <> Attributes surrounded by quotation marks A string containing special characters may be surrounded by “ <![CDATA[  ]>” <note type=“urgent”>  <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
AJAX :  Huh? Asynchronous JavaScript and XML (AJAX) Allows for asynchronous interaction with a web server Enables refreshes of only portions of content that the user is interacting with Creates a faster, more pleasant user experience Arguably the most important part of “Web 2.0”
AJAX : Cuts down on user wait time Uses client to offload some work from the server Asynchronous operation
AJAX :  XMLHTTPRequest This object makes the whole thing possible Not available in IE (in their defense, they invented the idea and implemented it first) use the ActiveX object  “Microsoft.XMLHTTP” Sends a request to a web server complete with headers and parameters Uses callback methods for status changes
Step 1)  Creating Request var httpRequest; try { httpRequest = new XMLHttpRequest(); } catch (trymicrosoft) { try { httpRequest = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;); } catch (othermicrosoft) { try { httpRequest = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); } catch (failed) { httpRequest = false; } } } if (!httpRequest ) alert(&quot;Error initializing XMLHttpRequest!&quot;);
Step 2)  Sending Request function sendRequest() { url=&quot;getflickrranking.php?word=dog&quot;; httpRequest.open(&quot;GET&quot;, url, true); httpRequest.onreadystatechange = processRequest; httpRequest.send(null);  }
XMLHTTP : Methods Method Description abort() Stops the current request getAllResponseHeaders() Returns complete set of headers (labels and values) as a string getResponseHeader(&quot;headerLabel&quot;) Returns the string value of a single header label open(&quot;method&quot;, &quot;URL&quot;[, asyncFlag[, &quot;userName&quot;[, &quot;password&quot;]]]) Assigns destination URL, method, and other optional attributes of a pending request send(content) Transmits the request, optionally with postable string or DOM object data setRequestHeader(&quot;label&quot;, &quot;value&quot;) Assigns a label/value pair to the header to be sent with a request
XMLHTTP : Properties Property Description onreadystatechange Event handler for an event that fires at every state change readyState Object status integer: 0 = uninitialized 1 = loading 2 = loaded 3 = interactive 4 = complete responseText String version of data returned from server process responseXML DOM-compatible document object of data returned from server process status Numeric code returned by server, such as 404 for &quot;Not Found&quot; or 200 for &quot;OK&quot; statusText String message accompanying the status code
Step 3)  Handling Response function processRequest() {     if (httpRequest.readyState == 4)     {         if(httpRequest.status == 200)         {    //process request here          }          else         {              alert(&quot;Error loading page\n&quot; + httpRequest.status + &quot;:&quot; + httpRequest.statusText);         }      }    }
Step 4)  Processing Response // in process request function var photo = httpRequest.responseXML.getElementsByTagName(&quot;photo&quot;)[1]; var id = photo.getAttribute(&quot;id&quot;); var owner = photo.getAttribute(&quot;owner&quot;); var secret = photo.getAttribute(&quot;secret&quot;); var server = photo.getAttribute(&quot;server&quot;); var title = photo.getAttribute(&quot;title&quot;); document.getElementById(&quot;imgDIV&quot;).innerHTML = '<strong>' + title + '</strong>'; var img = document.createElement('img'); img.setAttribute('src', 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg'); document.getElementById(&quot;imgDIV&quot;).appendChild(img);
XML : Useful Methods/Members element.childNodes[n] element.firstChild element.nodeValue() element.nodeName() element.attributes() element.getAttribute(“attributeName”); document.getElementsByTagName(“tagName”) More:  http://developer.mozilla.org/en/docs/Gecko_DOM_Reference
AJAX: Challenge #1 Using skeleton code, make an image search  Make an input box, have user input word, press search button, send the AJAX request When AJAX request returns, update a div below the search box with the image results nicely formatted Bonus #1:  Show all 5 image results (for loop!) at each different size, nicely formatted Bonus #2:  Illustrate user-inputted name with images (search for letters on Flickr)
AJAX : Design Considerations http://ajaxian.com/archives/ajax-experience-day-3-bill-scott-on-ajax-design-patterns-and-principles Users don’t always notice sections of the page have updated – consider coloring or somehow marking newly updated parts, especially if small Users aren’t used to clicking on a button and having nothing happen – show a loading indicator when the request has been sent, when its done processing, remove it ( http://www.ajaxload.info/  - generate a custom gif)  “ If you writing a user interface,  make sure it responds in 1/10th of a second ”
Google Gadgets AJAX! Google Gadgets has its own asynchronous functions for getting data: IG_FetchContent(url, func)  IG_FetchXMLContent(url, func)  Simplifies GET requests for Google Gadgets, eliminates ~12 lines of code
Google Gadgets AJAX:  Example <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>  <Module>  <ModulePrefs title=&quot;Music Mash&quot; height=&quot;300&quot; scaling=&quot;false&quot; />  <Content type=&quot;html&quot;>  <script language=&quot;javascript&quot; type=&quot;text/javascript&quot;>  function sendRequest() { url = &quot;getflickrranking.php?word=dog&quot;; _IG_FetchXMLContent(url,processRequest);  } function processRequest() {      if (httpRequest.readyState == 4)     {       if(httpRequest.status == 200)         {   //process request          }          else         {              alert(&quot;Error loading page\n&quot; + httpRequest.status + &quot;:&quot; + httpRequest.statusText);         }      }    } var newDiv = Document.createElement(&quot;div&quot;); newDiv.id = &quot;imgDiv&quot;; document.body.onload = sendRequest; </script>  ]]>  </Content>  </Module>

More Related Content

What's hot (20)

ODP
JavaScript and jQuery Fundamentals
BG Java EE Course
 
PDF
Getting Started with DOM
Hernan Mammana
 
PPT
Javascript: Ajax & DOM Manipulation v1.2
borkweb
 
PPT
KMUTNB - Internet Programming 4/7
phuphax
 
PDF
ePUB 3 and Publishing e-books
Kerem Karatal
 
PDF
JavaScript DOM & event
Borey Lim
 
PPT
JavaScript & Dom Manipulation
Mohammed Arif
 
PPTX
HTML/CSS/java Script/Jquery
FAKHRUN NISHA
 
PPT
C5 Javascript
Vlad Posea
 
PPTX
Introduction to Html5, css, Javascript and Jquery
valuebound
 
PPT
A quick guide to Css and java script
AVINASH KUMAR
 
PDF
Front End Good Practices
Hernan Mammana
 
KEY
HTML presentation for beginners
jeroenvdmeer
 
PPTX
IPW HTML course
Vlad Posea
 
PPT
Learn javascript easy steps
prince Loffar
 
PPTX
Javascript
Sun Technlogies
 
ODP
Introduction of Html/css/js
Knoldus Inc.
 
PPTX
HTML, CSS And JAVASCRIPT!
Syahmi RH
 
PPT
Eugene Andruszczenko: jQuery
Refresh Events
 
PPT
JSP Custom Tags
BG Java EE Course
 
JavaScript and jQuery Fundamentals
BG Java EE Course
 
Getting Started with DOM
Hernan Mammana
 
Javascript: Ajax & DOM Manipulation v1.2
borkweb
 
KMUTNB - Internet Programming 4/7
phuphax
 
ePUB 3 and Publishing e-books
Kerem Karatal
 
JavaScript DOM & event
Borey Lim
 
JavaScript & Dom Manipulation
Mohammed Arif
 
HTML/CSS/java Script/Jquery
FAKHRUN NISHA
 
C5 Javascript
Vlad Posea
 
Introduction to Html5, css, Javascript and Jquery
valuebound
 
A quick guide to Css and java script
AVINASH KUMAR
 
Front End Good Practices
Hernan Mammana
 
HTML presentation for beginners
jeroenvdmeer
 
IPW HTML course
Vlad Posea
 
Learn javascript easy steps
prince Loffar
 
Javascript
Sun Technlogies
 
Introduction of Html/css/js
Knoldus Inc.
 
HTML, CSS And JAVASCRIPT!
Syahmi RH
 
Eugene Andruszczenko: jQuery
Refresh Events
 
JSP Custom Tags
BG Java EE Course
 

Similar to AJAX Workshop Notes (20)

PPT
Ajax ppt
Sanmuga Nathan
 
PPT
Ajax Ppt
Hema Prasanth
 
PPT
Ajax
Pranay Rana
 
PPT
Ajax
Pranay Rana
 
PPT
Ajax Fundamentals Web Applications
dominion
 
PPT
Ajax presentation
engcs2008
 
PPT
Ajax
Rathan Raj
 
PPT
Introducing Struts 2
wiradikusuma
 
ODP
jQuery : Talk to server with Ajax
Wildan Maulana
 
PDF
Core Java tutorial at Unit Nexus
Unit Nexus Pvt. Ltd.
 
PPT
Ajax Introduction
Oliver Cai
 
PPT
Enhance Web Performance
Adam Lu
 
PPT
AJAX
Gouthaman V
 
PPT
AJAX
Gouthaman V
 
PPT
Struts2
yuvalb
 
PPT
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
PPT
JavaScript
Doncho Minkov
 
PPT
Ajax
rahmed_sct
 
PPT
Ajax tutorial by bally chohan
WebVineet
 
PPT
Ajax
devisp
 
Ajax ppt
Sanmuga Nathan
 
Ajax Ppt
Hema Prasanth
 
Ajax
Pranay Rana
 
Ajax
Pranay Rana
 
Ajax Fundamentals Web Applications
dominion
 
Ajax presentation
engcs2008
 
Ajax
Rathan Raj
 
Introducing Struts 2
wiradikusuma
 
jQuery : Talk to server with Ajax
Wildan Maulana
 
Core Java tutorial at Unit Nexus
Unit Nexus Pvt. Ltd.
 
Ajax Introduction
Oliver Cai
 
Enhance Web Performance
Adam Lu
 
AJAX
Gouthaman V
 
AJAX
Gouthaman V
 
Struts2
yuvalb
 
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
JavaScript
Doncho Minkov
 
Ajax
rahmed_sct
 
Ajax tutorial by bally chohan
WebVineet
 
Ajax
devisp
 
Ad

More from Pamela Fox (20)

PDF
Teaching Programming Online
Pamela Fox
 
PDF
Engineering culture
Pamela Fox
 
KEY
Django Admin: Widgetry & Witchery
Pamela Fox
 
PDF
A Year of Hermit Hacking
Pamela Fox
 
PDF
The Developer Experience
Pamela Fox
 
PDF
Making JavaScript Libraries More Approachable
Pamela Fox
 
PPT
How I became a born again vegetable-tarian
Pamela Fox
 
KEY
The Developer Experience
Pamela Fox
 
PPT
No, Really, I'm Shy
Pamela Fox
 
PPT
Writing Apps the Google-y Way (Brisbane)
Pamela Fox
 
PPT
Writing Apps the Google-y Way
Pamela Fox
 
PPT
The Wonders of the "Onesie"
Pamela Fox
 
PPT
I’M A Barbie Girl In A CS World
Pamela Fox
 
PPT
Google Wave 20/20: Product, Protocol, Platform
Pamela Fox
 
PPT
Collaborative Mapping with Google Wave
Pamela Fox
 
PPT
Google Products: Deep Dive on Google Maps
Pamela Fox
 
PPT
Google Products & Google Maps
Pamela Fox
 
PPT
Mashups & APIs
Pamela Fox
 
PPT
A World of Words
Pamela Fox
 
PPT
Web APIs & Google APIs
Pamela Fox
 
Teaching Programming Online
Pamela Fox
 
Engineering culture
Pamela Fox
 
Django Admin: Widgetry & Witchery
Pamela Fox
 
A Year of Hermit Hacking
Pamela Fox
 
The Developer Experience
Pamela Fox
 
Making JavaScript Libraries More Approachable
Pamela Fox
 
How I became a born again vegetable-tarian
Pamela Fox
 
The Developer Experience
Pamela Fox
 
No, Really, I'm Shy
Pamela Fox
 
Writing Apps the Google-y Way (Brisbane)
Pamela Fox
 
Writing Apps the Google-y Way
Pamela Fox
 
The Wonders of the "Onesie"
Pamela Fox
 
I’M A Barbie Girl In A CS World
Pamela Fox
 
Google Wave 20/20: Product, Protocol, Platform
Pamela Fox
 
Collaborative Mapping with Google Wave
Pamela Fox
 
Google Products: Deep Dive on Google Maps
Pamela Fox
 
Google Products & Google Maps
Pamela Fox
 
Mashups & APIs
Pamela Fox
 
A World of Words
Pamela Fox
 
Web APIs & Google APIs
Pamela Fox
 
Ad

Recently uploaded (20)

PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Digital Circuits, important subject in CS
contactparinay1
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 

AJAX Workshop Notes

  • 1. Sponsored by Upsilon Pi Epsilon The Computer Science Honors Society XML and AJAX
  • 2. XML : Basics XML stands for E X tensible M arkup L anguage XML is a markup language much like HTML XML was designed to describe data XML tags are not predefined. You must define your own tags XML should use a Document Type Definition (DTD) or an XML Schema to describe the data XML is a W3C Recommendation HTML is about displaying information, while XML is about describing information. XML doesn’t do anything itself- You do something with it. Source: http://www.w3schools.com/xml/xml_whatis.asp
  • 3. XML : Syntax & Example Tags open and close with <> Attributes surrounded by quotation marks A string containing special characters may be surrounded by “ <![CDATA[ ]>” <note type=“urgent”> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 4. AJAX : Huh? Asynchronous JavaScript and XML (AJAX) Allows for asynchronous interaction with a web server Enables refreshes of only portions of content that the user is interacting with Creates a faster, more pleasant user experience Arguably the most important part of “Web 2.0”
  • 5. AJAX : Cuts down on user wait time Uses client to offload some work from the server Asynchronous operation
  • 6. AJAX : XMLHTTPRequest This object makes the whole thing possible Not available in IE (in their defense, they invented the idea and implemented it first) use the ActiveX object “Microsoft.XMLHTTP” Sends a request to a web server complete with headers and parameters Uses callback methods for status changes
  • 7. Step 1) Creating Request var httpRequest; try { httpRequest = new XMLHttpRequest(); } catch (trymicrosoft) { try { httpRequest = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;); } catch (othermicrosoft) { try { httpRequest = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); } catch (failed) { httpRequest = false; } } } if (!httpRequest ) alert(&quot;Error initializing XMLHttpRequest!&quot;);
  • 8. Step 2) Sending Request function sendRequest() { url=&quot;getflickrranking.php?word=dog&quot;; httpRequest.open(&quot;GET&quot;, url, true); httpRequest.onreadystatechange = processRequest; httpRequest.send(null); }
  • 9. XMLHTTP : Methods Method Description abort() Stops the current request getAllResponseHeaders() Returns complete set of headers (labels and values) as a string getResponseHeader(&quot;headerLabel&quot;) Returns the string value of a single header label open(&quot;method&quot;, &quot;URL&quot;[, asyncFlag[, &quot;userName&quot;[, &quot;password&quot;]]]) Assigns destination URL, method, and other optional attributes of a pending request send(content) Transmits the request, optionally with postable string or DOM object data setRequestHeader(&quot;label&quot;, &quot;value&quot;) Assigns a label/value pair to the header to be sent with a request
  • 10. XMLHTTP : Properties Property Description onreadystatechange Event handler for an event that fires at every state change readyState Object status integer: 0 = uninitialized 1 = loading 2 = loaded 3 = interactive 4 = complete responseText String version of data returned from server process responseXML DOM-compatible document object of data returned from server process status Numeric code returned by server, such as 404 for &quot;Not Found&quot; or 200 for &quot;OK&quot; statusText String message accompanying the status code
  • 11. Step 3) Handling Response function processRequest() {     if (httpRequest.readyState == 4)     {         if(httpRequest.status == 200)         { //process request here          }          else         {              alert(&quot;Error loading page\n&quot; + httpRequest.status + &quot;:&quot; + httpRequest.statusText);         }      }    }
  • 12. Step 4) Processing Response // in process request function var photo = httpRequest.responseXML.getElementsByTagName(&quot;photo&quot;)[1]; var id = photo.getAttribute(&quot;id&quot;); var owner = photo.getAttribute(&quot;owner&quot;); var secret = photo.getAttribute(&quot;secret&quot;); var server = photo.getAttribute(&quot;server&quot;); var title = photo.getAttribute(&quot;title&quot;); document.getElementById(&quot;imgDIV&quot;).innerHTML = '<strong>' + title + '</strong>'; var img = document.createElement('img'); img.setAttribute('src', 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg'); document.getElementById(&quot;imgDIV&quot;).appendChild(img);
  • 13. XML : Useful Methods/Members element.childNodes[n] element.firstChild element.nodeValue() element.nodeName() element.attributes() element.getAttribute(“attributeName”); document.getElementsByTagName(“tagName”) More: http://developer.mozilla.org/en/docs/Gecko_DOM_Reference
  • 14. AJAX: Challenge #1 Using skeleton code, make an image search Make an input box, have user input word, press search button, send the AJAX request When AJAX request returns, update a div below the search box with the image results nicely formatted Bonus #1: Show all 5 image results (for loop!) at each different size, nicely formatted Bonus #2: Illustrate user-inputted name with images (search for letters on Flickr)
  • 15. AJAX : Design Considerations http://ajaxian.com/archives/ajax-experience-day-3-bill-scott-on-ajax-design-patterns-and-principles Users don’t always notice sections of the page have updated – consider coloring or somehow marking newly updated parts, especially if small Users aren’t used to clicking on a button and having nothing happen – show a loading indicator when the request has been sent, when its done processing, remove it ( http://www.ajaxload.info/ - generate a custom gif) “ If you writing a user interface, make sure it responds in 1/10th of a second ”
  • 16. Google Gadgets AJAX! Google Gadgets has its own asynchronous functions for getting data: IG_FetchContent(url, func) IG_FetchXMLContent(url, func) Simplifies GET requests for Google Gadgets, eliminates ~12 lines of code
  • 17. Google Gadgets AJAX: Example <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?> <Module> <ModulePrefs title=&quot;Music Mash&quot; height=&quot;300&quot; scaling=&quot;false&quot; /> <Content type=&quot;html&quot;> <script language=&quot;javascript&quot; type=&quot;text/javascript&quot;> function sendRequest() { url = &quot;getflickrranking.php?word=dog&quot;; _IG_FetchXMLContent(url,processRequest); } function processRequest() {      if (httpRequest.readyState == 4)     {       if(httpRequest.status == 200)         {   //process request          }          else         {              alert(&quot;Error loading page\n&quot; + httpRequest.status + &quot;:&quot; + httpRequest.statusText);         }      }    } var newDiv = Document.createElement(&quot;div&quot;); newDiv.id = &quot;imgDiv&quot;; document.body.onload = sendRequest; </script> ]]> </Content> </Module>