SlideShare a Scribd company logo
1 of 58
An Introduction To Ajax
              Alex Russell
     Project Lead, The Dojo Toolkit
         alex@dojotoolkit.org
These Slides Are Online:
            http://alex.dojotoolkit.org



   Tarball Of Demo Code:
http://alex.dojotoolkit.org/wp-content/demos.tar.gz
Please Ask Questions
Odds are someone else is wondering the same thing
What We’ll Cover

• What Ajax is
• What Ajax is not
• The fundamentals of Ajax
• How to build better experiences with Ajax
• Tools to make Ajax development easier
How We’ll Get There

• Demos
• Deconstruction
• Code examples
• Introduction to debugging tools
What You’ll Walk Away With
  • Enough code to be dangerous
  • Enough knowledge not to be
  • Tools of the trade
  • Places to look when you get stuck
  • How it all fits together
  • The lowdown on “what’s next”
What Is Ajax?
• New name, old tech
• Technique for increasing UI responsiveness
• Incremental, in-place updates to a page
• Updates a result of user actions
• Preserves you reach
 • No plugins, standards based
• Browser as protocol participant
Why Ajax Now?
• The browsers stabalized
• The DOM is more-or-less implemented
• HTML and CSS are tapped out
 • At the limit of resonsiveness and usability
• REST and SOAP are handy endpoints
• What if the browser could be just another
  client?
When Is Ajax The
       Answer?
• When targeting majority browsers
  exclusively or can write two versions
• When you interface “feels” heavy
• When the competition is using Ajax
 • They will be soon!
• When it can make users’ lives better but
  not worse
When Is Ajax Bad?
• When it breaks the freaking back button
• When it hinders accessibility
• When it disorients users
 • “jumping blocks”
• When it fails silently
• When it ignores indempotency
Remember Your Users
Ajax that doesn’t build better experiences is dumb
Auto Save
Grab the Chicken!
• Surprisingly intuitive experiences
• Demo Uses:
 • Simple structural HTML elements
 • Basic event handling
 • Background REST requests
• Get out of the user’s way!
Dissecting Auto Save

• XMLHTTP introduced
 • browser incompatibilities papered over
• Return XML traversed to get data
• Basic DOM manipulation
• ~150 lines of procedural JavaScript
var progIds = [
                           'Msxml2.XMLHTTP',

   
   
   



           'Microsoft.XMLHTTP',

   
   
   



           'Msxml2.XMLHTTP.4.0'];

   
   
   var http = null;

   
   
   var last_e = null;


   
   
   try{ http = new XMLHttpRequest(); }catch(e){}


   
   
   // IE branch

   
   
   /*@cc_on @*/

   
   
   /*@if (@_jscript_version >= 5)

   
   
   if(!http){

   
   
   
 for(var i=0; i<progIds.length; ++i){

   
   
   
 
 var objectType = progIds[i];

   
   
   
 
 try{

   
   
   
 
 
 http = new ActiveXObject(objectType);

   
   
   
 
 }catch(e){

   
   
   
 
 
 last_e = e;

   
   
   

}

   
   
   
}

   
   
   }

   
   
   @end @*/
Dissection contd.
• Basic DOM manipulation
• Getting “handles” to nodes
 • getElementsByTagName()
 • getElementById()
• Creating elements - example
• Deleting elements - example
• Moving elements around - example
• Changing the look of things - example
Scheduled Saves

• HTTP POST
 • We’re modifying data
• setInterval() for occasional execution
• Events hard-wired to IDs
• This code is brittle and hard to reuse
More on XMLHTTP
• Sync or Async communication
• Simple callback scheme for status
• Can return either text or XML doc
• Uses one of 2 available sockets
 • not x-domain
• Return order NOT guaranteed
• Interface NOT a standard (yet)
Ajax “quirks”
• Synchronous requests halt browser
• Picky about response Content-Type
• Some verbs problematic (HEAD, PUT)
• File upload not available cross-browser
 • handled w/ iframes and form hacks
• Bugs:
 • Caching (IE and FF 1.5 do, FF 1.0 doesn’t)
 • IE: which MSXML did I really get?
What About Iframes?
• Used extensively by earlier toolkits
• Highly portable (works on 4.0 browsers)
• IE “Phantom Click”
• onload handler not reliable
• Only way to upload files reliably
• Async only
Design Decision:
      What To Send?
• XML
• plain/text
 • HTML
 • JavaScript (JSON)
“It Depends”

• HTML
 • Easy to insert into document (fast!)
 • Can return as just a string, easy to debug
 • Portability problems
 • Implies replacement, not update
contd.
• XML
 • Usually supported, MUST use “text/xml”
 • Doesn’t tie your server to your
    rendering
 • Need to transform on client
 • XSLT can be very fast
 • Very large on the wire
contd.
• Plain text
• JavaScript/JSON
 • Smallest for large data sets
 • Fastest parsing
 • Native language of your scripting
    environment
 • Constructing UI can be slower
 • App more likely to “speak” XML
Improving Auto Save
Experience
       Improvements
• Only auto-save after things change
 • Avoid “twitchyness”
• Smoother notification
• Handle unavailable network
 • Save to cookie as backup
Code Improvements

• Less browser quirk juggling
• Less brittle event/node linkage
• Animations for transitions
• A reusable auto-save component
• Easier to instantiate
Toolkits To The Resuce!
• Dojo:
 • Save data with dojo.io.bind()
 • Generic events with dojo.event.connect()
 • Animation and component support
• Prototype:
 • Save data with Ajax.Request
 • Portable events with Event.observe()
Other Quality Toolkits
• Open Source
 • MochiKit
 • YUI
 • Scriptaculous (builds on Prototype)
• Closed Source
 • TurboWidgets (based on Dojo)
 • Bindows
 • Backbase
Auto Save With Prototype
Debugging: A Digression
Basic Debugging Tools
• Your tenacity
• Google
• Standards references
• Mozilla, Safari, Opera JavaScript consoles
• IE Script Debugger
• Rhino or WSH for basic langauge problems
Advanced Debugging
          Tools
•                             •
    Firebug                       Virtualization

•                             •
    LiveHTTPHeaders               VNC/RDP/X11

•                             •
    Ethereal                      Fiddler proxy

•                             •
    Venkman                       Web Developer Toolbar

•                                 •
    Microsoft Script Editor           Firefox

•                                 •
    Squarefree JS shell               IE
    bookmarklet
When In Doubt,
Watch The Traffic
85+% Of Your Users
    Still Use IE
Auto Save With Dojo
Making It A Component

• Auto-Save for any <textarea>
• Why widgets?
 • Automatic property binding
 • Modularization
 • Easier to re-use
Auto Save Dojo Widget
JavaScript: A Digression
It Works Now
• Not a “toy” language
• Dynamic, functional (has closures)
• Classes and inheritance
• Ubiquitous: browser, stand alone, flash, etc.
• Debuggers available
• Can be modularized/packaged
• Libraries provide packaging, AOP, etc.
The Chameleon Of
      Languages
• Never what you expect
• Whatever you make of it
 • Imperative to imperative programmers
 • OO (with quirks) to OO programmers
 • Functional to Functional hackers
Language Features
•                            •
    Lexical scope                OOP via constructor
                                 closures and prototype
•                                inheritance
    Functions are objects

                             •
•                                Some interpreters
    Functions are closures
                                 support continuations
•   Anonymous function
                             •   C-style syntax
    support

•   Delegation via the
    prototype chain
OOP in JS

• Prototype-based inheritance
• Not class-based!
• Prototype chain is method and property
  delegation
The Prototype Chain
function FooClass(ctorArg1, ctorArg2){
}


FooClass.prototype.foo = “foo”;
FooClass.prototype.bar = “bar”;


var baz = new FooClass();
baz.foo = “my own foo”;


var thud = new FooClass();
thud.foo == “foo”;
Mixins For Multiple
            Inheritance
// “interfaces that actually do something”
namespace.mixinClass = function(){
    this.foo = “foo”;
    this.bar = function(){
        alert(this.foo);
    }
};
function thingerClass(){
    namespace.mixinClass.call(this);
}
(new thingerClass()).foo == “foo”;
Rant: The Open Web
The Open Web Is
  Under Attack
The Web Won Because
 It Cost Less To Build
• Markup is the fastest way to build UIs
• Text, end-to-end
 • Remixable
• Open Specs allow multiple renderers
• Royalty-free licensing of IP a key tennant
Who Wouldn’t Love To
 Control The Web?
• Now that it’s valuable, there’s money to be
  had
• Closed, markup-based systems with single
  renderers threaten our ability to build
  freely
Ajax Is Helping To Keep
    The Web Open
• Still text all the way
• Open protocols: HTTP
• Standards-based tools, multiple clients
• Still not an experience that’s competitive
  with closed solutions
Browser Vendors Do
 What You Demand
Nothing More.
Often Much Less.
Make Your Voice Heard
• Support minority browsers in your apps
• Use better browsers
• Vote for bugs in Open Source renderers
• File bugs for missing features in closed
  clients
• Blog
• Comment on vendor blogs
The Open Web Can
     Still Win
What’s Next
• Low-latency data transfer: “Comet”
• Continued JavaScript ubiquity
 • Shipping with next JDK
• E4X
• Blurred desktop/web lines
• Cross-domain API usage from the browser
Where To Look For
        Answers
•                               •
    JavaScript, The Definitive       Mozilla DOM Reference
    Guide
                                •   Ajaxpatterns.org
•   W3C DOM Spec
                                •   Toolkit-specific lists and
•   Ecma 262-3 Spec                 forums

•                               •
    Quirksmode.org                  javascript.faqts.com

•                               •
    MSDN DHTML                      Browser source code
    References
                                •   Toolkit source code
Q&A
Send private questions to:
  alex@dojotoolkit.org
Thanks For Showing Up!

More Related Content

What's hot

PPW2007 - Continuity Project
PPW2007 - Continuity ProjectPPW2007 - Continuity Project
PPW2007 - Continuity Projectawwaiid
 
Unobtrusive JavaScript with jQuery
Unobtrusive JavaScript with jQueryUnobtrusive JavaScript with jQuery
Unobtrusive JavaScript with jQuerySimon Willison
 
Defcon 20-zulla-improving-web-vulnerability-scanning
Defcon 20-zulla-improving-web-vulnerability-scanningDefcon 20-zulla-improving-web-vulnerability-scanning
Defcon 20-zulla-improving-web-vulnerability-scanningzulla
 
Coldfusion
ColdfusionColdfusion
ColdfusionRam
 
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQLHTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQLUlf Wendel
 
XML and Web Services with Groovy
XML and Web Services with GroovyXML and Web Services with Groovy
XML and Web Services with GroovyPaul King
 
Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)Peter Lubbers
 
WebPagetest Power Users - Velocity 2014
WebPagetest Power Users - Velocity 2014WebPagetest Power Users - Velocity 2014
WebPagetest Power Users - Velocity 2014Patrick Meenan
 
Node.js, toy or power tool?
Node.js, toy or power tool?Node.js, toy or power tool?
Node.js, toy or power tool?Ovidiu Dimulescu
 
A first look into the Project Loom in Java
A first look into the Project Loom in JavaA first look into the Project Loom in Java
A first look into the Project Loom in JavaLukas Steinbrecher
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best PracticesDavid Arcos
 
Myphp-busters: symfony framework
Myphp-busters: symfony frameworkMyphp-busters: symfony framework
Myphp-busters: symfony frameworkStefan Koopmanschap
 
Hands on performance testing and analysis with web pagetest
Hands on performance testing and analysis with web pagetestHands on performance testing and analysis with web pagetest
Hands on performance testing and analysis with web pagetestPatrick Meenan
 
Developing web applications in 2010
Developing web applications in 2010Developing web applications in 2010
Developing web applications in 2010Ignacio Coloma
 

What's hot (19)

PPW2007 - Continuity Project
PPW2007 - Continuity ProjectPPW2007 - Continuity Project
PPW2007 - Continuity Project
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Unobtrusive JavaScript with jQuery
Unobtrusive JavaScript with jQueryUnobtrusive JavaScript with jQuery
Unobtrusive JavaScript with jQuery
 
Defcon 20-zulla-improving-web-vulnerability-scanning
Defcon 20-zulla-improving-web-vulnerability-scanningDefcon 20-zulla-improving-web-vulnerability-scanning
Defcon 20-zulla-improving-web-vulnerability-scanning
 
Coldfusion
ColdfusionColdfusion
Coldfusion
 
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQLHTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
 
XML and Web Services with Groovy
XML and Web Services with GroovyXML and Web Services with Groovy
XML and Web Services with Groovy
 
Edge of the Web
Edge of the WebEdge of the Web
Edge of the Web
 
Dust.js
Dust.jsDust.js
Dust.js
 
Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)
 
WebPagetest Power Users - Velocity 2014
WebPagetest Power Users - Velocity 2014WebPagetest Power Users - Velocity 2014
WebPagetest Power Users - Velocity 2014
 
Node.js, toy or power tool?
Node.js, toy or power tool?Node.js, toy or power tool?
Node.js, toy or power tool?
 
A first look into the Project Loom in Java
A first look into the Project Loom in JavaA first look into the Project Loom in Java
A first look into the Project Loom in Java
 
Flash And Dom
Flash And DomFlash And Dom
Flash And Dom
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best Practices
 
Myphp-busters: symfony framework
Myphp-busters: symfony frameworkMyphp-busters: symfony framework
Myphp-busters: symfony framework
 
Hands on performance testing and analysis with web pagetest
Hands on performance testing and analysis with web pagetestHands on performance testing and analysis with web pagetest
Hands on performance testing and analysis with web pagetest
 
Developing web applications in 2010
Developing web applications in 2010Developing web applications in 2010
Developing web applications in 2010
 

Viewers also liked

JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)Raghu nath
 
Open Ldap Integration and Configuration with Lifray 6.2
Open Ldap Integration and Configuration with Lifray 6.2Open Ldap Integration and Configuration with Lifray 6.2
Open Ldap Integration and Configuration with Lifray 6.2Vinaykumar Hebballi
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajaxNir Elbaz
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slidesSmithss25
 

Viewers also liked (6)

JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
 
Open Ldap Integration and Configuration with Lifray 6.2
Open Ldap Integration and Configuration with Lifray 6.2Open Ldap Integration and Configuration with Lifray 6.2
Open Ldap Integration and Configuration with Lifray 6.2
 
Json vs Gson vs Jackson
Json vs Gson vs JacksonJson vs Gson vs Jackson
Json vs Gson vs Jackson
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 

Similar to Ajax Tutorial

Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Libraryjeresig
 
Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008rajivmordani
 
Web Development: The Next Five Years
Web Development: The Next Five YearsWeb Development: The Next Five Years
Web Development: The Next Five Yearssneeu
 
Performance Improvements In Browsers
Performance Improvements In BrowsersPerformance Improvements In Browsers
Performance Improvements In BrowsersGoogleTecTalks
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsersjeresig
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for youSimon Willison
 
Javascript Framework Roundup FYB
Javascript Framework Roundup FYBJavascript Framework Roundup FYB
Javascript Framework Roundup FYBnukeevry1
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesSimon Willison
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overviewjeresig
 
javascript teach
javascript teachjavascript teach
javascript teachguest3732fa
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_Whiteguest3732fa
 
JavaScript Libraries (@Media)
JavaScript Libraries (@Media)JavaScript Libraries (@Media)
JavaScript Libraries (@Media)jeresig
 
Drupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQueryDrupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQueryMatt Butcher
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)jeresig
 
Application Architecture Trends
Application Architecture TrendsApplication Architecture Trends
Application Architecture TrendsSrini Penchikala
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Developmentwolframkriesing
 
Performance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScriptPerformance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScriptjeresig
 
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss ToolsPresentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss ToolsGanesh Samarthyam
 

Similar to Ajax Tutorial (20)

Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Library
 
Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008
 
Web Development: The Next Five Years
Web Development: The Next Five YearsWeb Development: The Next Five Years
Web Development: The Next Five Years
 
Performance Improvements In Browsers
Performance Improvements In BrowsersPerformance Improvements In Browsers
Performance Improvements In Browsers
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 
Javascript Framework Roundup FYB
Javascript Framework Roundup FYBJavascript Framework Roundup FYB
Javascript Framework Roundup FYB
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
 
javascript teach
javascript teachjavascript teach
javascript teach
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
 
JavaScript Libraries (@Media)
JavaScript Libraries (@Media)JavaScript Libraries (@Media)
JavaScript Libraries (@Media)
 
Drupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQueryDrupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQuery
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)
 
Application Architecture Trends
Application Architecture TrendsApplication Architecture Trends
Application Architecture Trends
 
iPhone & Java Web Services
iPhone & Java Web ServicesiPhone & Java Web Services
iPhone & Java Web Services
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Development
 
Performance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScriptPerformance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScript
 
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss ToolsPresentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
 
Http Status Report
Http Status ReportHttp Status Report
Http Status Report
 

More from oscon2007

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5oscon2007
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifmoscon2007
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Moleoscon2007
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashearsoscon2007
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swposcon2007
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Mythsoscon2007
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholisticoscon2007
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillipsoscon2007
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdatedoscon2007
 

More from oscon2007 (20)

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5
 
Os Borger
Os BorgerOs Borger
Os Borger
 
Os Harkins
Os HarkinsOs Harkins
Os Harkins
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifm
 
Os Bunce
Os BunceOs Bunce
Os Bunce
 
Yuicss R7
Yuicss R7Yuicss R7
Yuicss R7
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Mole
 
Os Fogel
Os FogelOs Fogel
Os Fogel
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashears
 
Os Tucker
Os TuckerOs Tucker
Os Tucker
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Myths
 
Os Kimsal
Os KimsalOs Kimsal
Os Kimsal
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Os Alrubaie
Os AlrubaieOs Alrubaie
Os Alrubaie
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillips
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdated
 

Recently uploaded

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

Ajax Tutorial

  • 1. An Introduction To Ajax Alex Russell Project Lead, The Dojo Toolkit alex@dojotoolkit.org
  • 2. These Slides Are Online: http://alex.dojotoolkit.org Tarball Of Demo Code: http://alex.dojotoolkit.org/wp-content/demos.tar.gz
  • 3. Please Ask Questions Odds are someone else is wondering the same thing
  • 4. What We’ll Cover • What Ajax is • What Ajax is not • The fundamentals of Ajax • How to build better experiences with Ajax • Tools to make Ajax development easier
  • 5. How We’ll Get There • Demos • Deconstruction • Code examples • Introduction to debugging tools
  • 6. What You’ll Walk Away With • Enough code to be dangerous • Enough knowledge not to be • Tools of the trade • Places to look when you get stuck • How it all fits together • The lowdown on “what’s next”
  • 7. What Is Ajax? • New name, old tech • Technique for increasing UI responsiveness • Incremental, in-place updates to a page • Updates a result of user actions • Preserves you reach • No plugins, standards based • Browser as protocol participant
  • 8. Why Ajax Now? • The browsers stabalized • The DOM is more-or-less implemented • HTML and CSS are tapped out • At the limit of resonsiveness and usability • REST and SOAP are handy endpoints • What if the browser could be just another client?
  • 9. When Is Ajax The Answer? • When targeting majority browsers exclusively or can write two versions • When you interface “feels” heavy • When the competition is using Ajax • They will be soon! • When it can make users’ lives better but not worse
  • 10. When Is Ajax Bad? • When it breaks the freaking back button • When it hinders accessibility • When it disorients users • “jumping blocks” • When it fails silently • When it ignores indempotency
  • 11. Remember Your Users Ajax that doesn’t build better experiences is dumb
  • 13. Grab the Chicken! • Surprisingly intuitive experiences • Demo Uses: • Simple structural HTML elements • Basic event handling • Background REST requests • Get out of the user’s way!
  • 14. Dissecting Auto Save • XMLHTTP introduced • browser incompatibilities papered over • Return XML traversed to get data • Basic DOM manipulation • ~150 lines of procedural JavaScript
  • 15. var progIds = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0']; var http = null; var last_e = null; try{ http = new XMLHttpRequest(); }catch(e){} // IE branch /*@cc_on @*/ /*@if (@_jscript_version >= 5) if(!http){ for(var i=0; i<progIds.length; ++i){ var objectType = progIds[i]; try{ http = new ActiveXObject(objectType); }catch(e){ last_e = e; } } } @end @*/
  • 16. Dissection contd. • Basic DOM manipulation • Getting “handles” to nodes • getElementsByTagName() • getElementById() • Creating elements - example • Deleting elements - example • Moving elements around - example • Changing the look of things - example
  • 17. Scheduled Saves • HTTP POST • We’re modifying data • setInterval() for occasional execution • Events hard-wired to IDs • This code is brittle and hard to reuse
  • 18. More on XMLHTTP • Sync or Async communication • Simple callback scheme for status • Can return either text or XML doc • Uses one of 2 available sockets • not x-domain • Return order NOT guaranteed • Interface NOT a standard (yet)
  • 19. Ajax “quirks” • Synchronous requests halt browser • Picky about response Content-Type • Some verbs problematic (HEAD, PUT) • File upload not available cross-browser • handled w/ iframes and form hacks • Bugs: • Caching (IE and FF 1.5 do, FF 1.0 doesn’t) • IE: which MSXML did I really get?
  • 20. What About Iframes? • Used extensively by earlier toolkits • Highly portable (works on 4.0 browsers) • IE “Phantom Click” • onload handler not reliable • Only way to upload files reliably • Async only
  • 21. Design Decision: What To Send? • XML • plain/text • HTML • JavaScript (JSON)
  • 22. “It Depends” • HTML • Easy to insert into document (fast!) • Can return as just a string, easy to debug • Portability problems • Implies replacement, not update
  • 23. contd. • XML • Usually supported, MUST use “text/xml” • Doesn’t tie your server to your rendering • Need to transform on client • XSLT can be very fast • Very large on the wire
  • 24. contd. • Plain text • JavaScript/JSON • Smallest for large data sets • Fastest parsing • Native language of your scripting environment • Constructing UI can be slower • App more likely to “speak” XML
  • 26. Experience Improvements • Only auto-save after things change • Avoid “twitchyness” • Smoother notification • Handle unavailable network • Save to cookie as backup
  • 27. Code Improvements • Less browser quirk juggling • Less brittle event/node linkage • Animations for transitions • A reusable auto-save component • Easier to instantiate
  • 28. Toolkits To The Resuce! • Dojo: • Save data with dojo.io.bind() • Generic events with dojo.event.connect() • Animation and component support • Prototype: • Save data with Ajax.Request • Portable events with Event.observe()
  • 29. Other Quality Toolkits • Open Source • MochiKit • YUI • Scriptaculous (builds on Prototype) • Closed Source • TurboWidgets (based on Dojo) • Bindows • Backbase
  • 30. Auto Save With Prototype
  • 32. Basic Debugging Tools • Your tenacity • Google • Standards references • Mozilla, Safari, Opera JavaScript consoles • IE Script Debugger • Rhino or WSH for basic langauge problems
  • 33. Advanced Debugging Tools • • Firebug Virtualization • • LiveHTTPHeaders VNC/RDP/X11 • • Ethereal Fiddler proxy • • Venkman Web Developer Toolbar • • Microsoft Script Editor Firefox • • Squarefree JS shell IE bookmarklet
  • 34. When In Doubt, Watch The Traffic
  • 35. 85+% Of Your Users Still Use IE
  • 37. Making It A Component • Auto-Save for any <textarea> • Why widgets? • Automatic property binding • Modularization • Easier to re-use
  • 38. Auto Save Dojo Widget
  • 40. It Works Now • Not a “toy” language • Dynamic, functional (has closures) • Classes and inheritance • Ubiquitous: browser, stand alone, flash, etc. • Debuggers available • Can be modularized/packaged • Libraries provide packaging, AOP, etc.
  • 41. The Chameleon Of Languages • Never what you expect • Whatever you make of it • Imperative to imperative programmers • OO (with quirks) to OO programmers • Functional to Functional hackers
  • 42. Language Features • • Lexical scope OOP via constructor closures and prototype • inheritance Functions are objects • • Some interpreters Functions are closures support continuations • Anonymous function • C-style syntax support • Delegation via the prototype chain
  • 43. OOP in JS • Prototype-based inheritance • Not class-based! • Prototype chain is method and property delegation
  • 44. The Prototype Chain function FooClass(ctorArg1, ctorArg2){ } FooClass.prototype.foo = “foo”; FooClass.prototype.bar = “bar”; var baz = new FooClass(); baz.foo = “my own foo”; var thud = new FooClass(); thud.foo == “foo”;
  • 45. Mixins For Multiple Inheritance // “interfaces that actually do something” namespace.mixinClass = function(){ this.foo = “foo”; this.bar = function(){ alert(this.foo); } }; function thingerClass(){ namespace.mixinClass.call(this); } (new thingerClass()).foo == “foo”;
  • 47. The Open Web Is Under Attack
  • 48. The Web Won Because It Cost Less To Build • Markup is the fastest way to build UIs • Text, end-to-end • Remixable • Open Specs allow multiple renderers • Royalty-free licensing of IP a key tennant
  • 49. Who Wouldn’t Love To Control The Web? • Now that it’s valuable, there’s money to be had • Closed, markup-based systems with single renderers threaten our ability to build freely
  • 50. Ajax Is Helping To Keep The Web Open • Still text all the way • Open protocols: HTTP • Standards-based tools, multiple clients • Still not an experience that’s competitive with closed solutions
  • 51. Browser Vendors Do What You Demand
  • 53. Make Your Voice Heard • Support minority browsers in your apps • Use better browsers • Vote for bugs in Open Source renderers • File bugs for missing features in closed clients • Blog • Comment on vendor blogs
  • 54. The Open Web Can Still Win
  • 55. What’s Next • Low-latency data transfer: “Comet” • Continued JavaScript ubiquity • Shipping with next JDK • E4X • Blurred desktop/web lines • Cross-domain API usage from the browser
  • 56. Where To Look For Answers • • JavaScript, The Definitive Mozilla DOM Reference Guide • Ajaxpatterns.org • W3C DOM Spec • Toolkit-specific lists and • Ecma 262-3 Spec forums • • Quirksmode.org javascript.faqts.com • • MSDN DHTML Browser source code References • Toolkit source code
  • 57. Q&A Send private questions to: alex@dojotoolkit.org