SlideShare a Scribd company logo
1 of 31
Introduction to AJAX & jQuery
Jon Tedesco




                                1
Outline
               Web Requests
                 GET &POST

               AJAX Basics

               JavaScript
                 Overview
                 Callbacks
                 AJAX

               jQuery
                 Features

               Demo

Jon Tedesco                    2
Web Requests
              GET & POST, Client & Server Perspectives


Jon Tedesco                                              3
A Basic Web Request

                                Client (Browser)
                                   Submit single web
                                    request
                                   Receive & render
                                    HTML
  Time




                                Server
                                   Receive request
                                   Return HTML

                                Static
                                   One request, no
                                    further interaction

Jon Tedesco                                               4
GET & POST: Summary

              GET                                 POST
               Retrieve data                      Modify or submit data

               Display data in URL                Data hidden from URL

               Example                            Example
                  Fetching a web page               Submitting a form


               Either allow passing parameters
                  How does each behave? When should we use one over the
                   other?

Jon Tedesco                                                                 5
A Basic Web Request

                                GET
                                  Most basic request
                                  Sent by browser for
                                   fetching a page

                                POST
  Time




                                  Often used for form
                                   data

                                Why?
                                  Simple
                                  Fast
                                  Idempotent


Jon Tedesco                                              6
GET & POST: Characteristics

              GET                           POST
               More usable                  More complex
                 GET requests can be
                  cached                        Slower
                 GET requests can remain
                  in the browser history     Secure (sort of)
                 GET requests can be           Parameters are not
                  bookmarked                     shown in URL
                 GET requests can be
                  distributed & shared
                                             Better for large amounts of
               URL length                    data
                 Prohibitive for large
                   requests                  Not sharable

Jon Tedesco                                                                 7
GET & POST: Best Practices

              GET                            POST
               Use for idempotent actions    Use for actions with side
                                               effects
               Use for AJAX                     Potential modify or
                  Fast                           delete

               Use for sharing links         Use for large data

               Example                       Use for sensitive data
                  YouTube
                                              Example
                  Google
                                                 Comments

Jon Tedesco                                                                8
GET & POST: From PHP

              GET                                     POST
               myserver/endpoint.php?foo=1&bar=word   myserver/endpoint.php




               Received as associative array in PHP

               Consider characteristics of each

Jon Tedesco                                                                   9
AJAX
              A high-level introduction


Jon Tedesco                               10
AJAX: Overview

               What is it?
                  Use JavaScript to send web requests after page load

                  Asynchronous JavaScript And XML


               Why use it?
                  Make site more interactive

                  Update content without reloading


               Example
                  Facebook Ticker


Jon Tedesco
AJAX: Diagram
                                 Client (Browser)
                                   Submit request
                                   No page reload
                                   Handle response

                                 Server (Google)
                                   Receive request
  Time




                                   Respond with some data
                                       HTML, JSON, XML, etc.

                                 Simply GET or POST requests
                                   Parameter data
                                   Receive & handle response
                                     from server

                                 How do we do this?
                                   JavaScript

Jon Tedesco                                                     12
JavaScript
              Key features & use with AJAX


Jon Tedesco                                  13
JavaScript: Introduction

               Runs on user’s browser
                 Place in <script> … </script>

                 Run on page load


               Basic language properties
                 Interpreted

                 Single-threaded



Jon Tedesco                                       14
JavaScript: Basics

               Language

                 Basic, readable
                   syntax

                 Automatic type
                   casting

                 Arrays, dictionaries

               Development

                 Console Demo
Jon Tedesco                              15
JavaScript: Functions

               Functions

                  First-class citizens

                  Associated with
                    scope

                  Callbacks

               JavaScript is built for
                 asynchronous
                 programming!


Jon Tedesco                               16
JavaScript: Browser Example




Jon Tedesco                                 17
JavaScript: AJAX Example

               Trigger JavaScript
                  On page load
                  On user event
                  On a timer
                  …

               Submit HTTP request

               Handle server
                response
                  Callbacks


Jon Tedesco                              18
JavaScript: AJAX Example
    JavaScript (triggered by event)   PHP (endpoint.php)




Jon Tedesco                                                19
jQuery
              Key features & use with AJAX


Jon Tedesco                                  20
jQuery: Motivation

               JavaScript can be challenging
                 Too much code for simple tasks
                 Browser inconsistency

               jQuery simplifies common tasks
                 DOM traversal & manipulation
                 Event handling
                 Animations
                 AJAX


Jon Tedesco                                        21
jQuery: Motivation

               jQuery is …
                 Fast

                 Concise

                 Lightweight

                 Multi-browser compatible

                 Widely used

                    Over 55% of 10,000 most-visited sites

                    Over half of all websites


Jon Tedesco                                                  22
jQuery: Basic Selectors

              Without jQuery                              With jQuery




                 DOM selection differs across browsers

                 Using jQuery, you can easily handle
                  element selections
                   Hide/show
                   Animate
                   Modify content
                   …

Jon Tedesco                                                             23
jQuery: DOM Manipulation & Animation


              Without jQuery       With jQuery




Jon Tedesco                                          24
jQuery: AJAX

              Without jQuery   With jQuery




Jon Tedesco                                  25
AJAX Demo

               Let’s write the code…
                 PHP endpoint

                 Empty web page

               Tools
                 jQuery

                 PHP

                 Google Chrome console


Jon Tedesco                               26
AJAX Demo



                          endpoint.php




     index.html
                          Console / JavaScript


Jon Tedesco                                      27
AJAX Demo



                          endpoint.php




     index.html


                          Console / JavaScript
Jon Tedesco                                      28
Summary
               Web Requests
                 GET &POST

               AJAX Basics

               JavaScript
                 Overview
                 Callbacks
                 AJAX

               jQuery
                 Features

               Demo

Jon Tedesco                    29
Questions?
Jon Tedesco




              30
References

                 GET v. POST
                     http://blog.teamtreehouse.com/the-definitive-guide-to-get-vs-post#disqus_thread
                     http://stackoverflow.com/questions/46585/when-do-you-use-post-and-when-do-you-use-get
                     http://www.jquery4u.com/ajax/key-differences-post/#.UIoD0Gl26QY

                 AJAX
                     http://scorebig.files.wordpress.com/2011/09/feed1.jpg
                     http://www.w3schools.com/ajax/ajax_intro.asp

                 JavaScript
                     http://en.wikipedia.org/wiki/JavaScript

                 jQuery
                     http://en.wikipedia.org/wiki/JQuery
                     http://www.sitepoint.com/jquery-used-on-50-percent-of-websites/
                     http://www.slideshare.net/arwid/jquery-4470993




Jon Tedesco                                                                                                   31

More Related Content

Similar to Introduction to AJAX

REST and JAX-RS
REST and JAX-RSREST and JAX-RS
REST and JAX-RSGuy Nir
 
SharePoint Performance Optimization In 10 Steps for the IT Professional
SharePoint Performance Optimization In 10 Steps for the IT ProfessionalSharePoint Performance Optimization In 10 Steps for the IT Professional
SharePoint Performance Optimization In 10 Steps for the IT ProfessionalJoel Oleson
 
Using AppEngine for Mobile Apps
Using AppEngine for Mobile AppsUsing AppEngine for Mobile Apps
Using AppEngine for Mobile AppsJunda Ong
 
Jetty 9 – The Next Generation Servlet Container
Jetty 9 – The Next Generation Servlet ContainerJetty 9 – The Next Generation Servlet Container
Jetty 9 – The Next Generation Servlet ContainerCodemotion
 
Even faster django
Even faster djangoEven faster django
Even faster djangoGage Tseng
 
How to build a rest api
How to build a rest apiHow to build a rest api
How to build a rest apiHoang Nguyen
 
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontendtkramar
 
Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questionsSujata Regoti
 
Lotusphere 2007 AD401 LEVERAGING AJAX FRAMEWORKS TO BUILD IBM LOTUS DOMINO WE...
Lotusphere 2007 AD401 LEVERAGING AJAX FRAMEWORKS TO BUILD IBM LOTUS DOMINO WE...Lotusphere 2007 AD401 LEVERAGING AJAX FRAMEWORKS TO BUILD IBM LOTUS DOMINO WE...
Lotusphere 2007 AD401 LEVERAGING AJAX FRAMEWORKS TO BUILD IBM LOTUS DOMINO WE...dominion
 
DEV301- Web Service Programming with WCF 3.5
DEV301- Web Service Programming with WCF 3.5DEV301- Web Service Programming with WCF 3.5
DEV301- Web Service Programming with WCF 3.5Eyal Vardi
 
When RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPWhen RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPMatthew Turland
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAnuchit Chalothorn
 
3 Hacks to Improve WordPress Performance
3 Hacks to Improve WordPress Performance3 Hacks to Improve WordPress Performance
3 Hacks to Improve WordPress PerformanceRF Studio
 
20150309 seven core principles of meteor
20150309 seven core principles of meteor20150309 seven core principles of meteor
20150309 seven core principles of meteorRick Wehrle
 
WebSockets On Fire
WebSockets On FireWebSockets On Fire
WebSockets On FireJef Claes
 
Silicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you RESTSilicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you RESTManish Pandit
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterDoris Chen
 
Tuning web performance
Tuning web performanceTuning web performance
Tuning web performanceGeorge Ang
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web PerformanceEric ShangKuan
 

Similar to Introduction to AJAX (20)

REST and JAX-RS
REST and JAX-RSREST and JAX-RS
REST and JAX-RS
 
SharePoint Performance Optimization In 10 Steps for the IT Professional
SharePoint Performance Optimization In 10 Steps for the IT ProfessionalSharePoint Performance Optimization In 10 Steps for the IT Professional
SharePoint Performance Optimization In 10 Steps for the IT Professional
 
Using AppEngine for Mobile Apps
Using AppEngine for Mobile AppsUsing AppEngine for Mobile Apps
Using AppEngine for Mobile Apps
 
Jetty 9 – The Next Generation Servlet Container
Jetty 9 – The Next Generation Servlet ContainerJetty 9 – The Next Generation Servlet Container
Jetty 9 – The Next Generation Servlet Container
 
Even faster django
Even faster djangoEven faster django
Even faster django
 
How to build a rest api
How to build a rest apiHow to build a rest api
How to build a rest api
 
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontend
 
Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questions
 
Lotusphere 2007 AD401 LEVERAGING AJAX FRAMEWORKS TO BUILD IBM LOTUS DOMINO WE...
Lotusphere 2007 AD401 LEVERAGING AJAX FRAMEWORKS TO BUILD IBM LOTUS DOMINO WE...Lotusphere 2007 AD401 LEVERAGING AJAX FRAMEWORKS TO BUILD IBM LOTUS DOMINO WE...
Lotusphere 2007 AD401 LEVERAGING AJAX FRAMEWORKS TO BUILD IBM LOTUS DOMINO WE...
 
DEV301- Web Service Programming with WCF 3.5
DEV301- Web Service Programming with WCF 3.5DEV301- Web Service Programming with WCF 3.5
DEV301- Web Service Programming with WCF 3.5
 
When RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPWhen RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTP
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web Services
 
3 Hacks to Improve WordPress Performance
3 Hacks to Improve WordPress Performance3 Hacks to Improve WordPress Performance
3 Hacks to Improve WordPress Performance
 
20150309 seven core principles of meteor
20150309 seven core principles of meteor20150309 seven core principles of meteor
20150309 seven core principles of meteor
 
WebSockets On Fire
WebSockets On FireWebSockets On Fire
WebSockets On Fire
 
Silicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you RESTSilicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you REST
 
Asif
AsifAsif
Asif
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
 
Tuning web performance
Tuning web performanceTuning web performance
Tuning web performance
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web Performance
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Recently uploaded (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

Introduction to AJAX

  • 1. Introduction to AJAX & jQuery Jon Tedesco 1
  • 2. Outline  Web Requests  GET &POST  AJAX Basics  JavaScript  Overview  Callbacks  AJAX  jQuery  Features  Demo Jon Tedesco 2
  • 3. Web Requests GET & POST, Client & Server Perspectives Jon Tedesco 3
  • 4. A Basic Web Request  Client (Browser)  Submit single web request  Receive & render HTML Time  Server  Receive request  Return HTML  Static  One request, no further interaction Jon Tedesco 4
  • 5. GET & POST: Summary GET POST  Retrieve data  Modify or submit data  Display data in URL  Data hidden from URL  Example  Example  Fetching a web page  Submitting a form  Either allow passing parameters  How does each behave? When should we use one over the other? Jon Tedesco 5
  • 6. A Basic Web Request  GET  Most basic request  Sent by browser for fetching a page  POST Time  Often used for form data  Why?  Simple  Fast  Idempotent Jon Tedesco 6
  • 7. GET & POST: Characteristics GET POST  More usable  More complex  GET requests can be cached  Slower  GET requests can remain in the browser history  Secure (sort of)  GET requests can be  Parameters are not bookmarked shown in URL  GET requests can be distributed & shared  Better for large amounts of  URL length data  Prohibitive for large requests  Not sharable Jon Tedesco 7
  • 8. GET & POST: Best Practices GET POST  Use for idempotent actions  Use for actions with side effects  Use for AJAX  Potential modify or  Fast delete  Use for sharing links  Use for large data  Example  Use for sensitive data  YouTube  Example  Google  Comments Jon Tedesco 8
  • 9. GET & POST: From PHP GET POST myserver/endpoint.php?foo=1&bar=word myserver/endpoint.php  Received as associative array in PHP  Consider characteristics of each Jon Tedesco 9
  • 10. AJAX A high-level introduction Jon Tedesco 10
  • 11. AJAX: Overview  What is it?  Use JavaScript to send web requests after page load  Asynchronous JavaScript And XML  Why use it?  Make site more interactive  Update content without reloading  Example  Facebook Ticker Jon Tedesco
  • 12. AJAX: Diagram  Client (Browser)  Submit request  No page reload  Handle response  Server (Google)  Receive request Time  Respond with some data  HTML, JSON, XML, etc.  Simply GET or POST requests  Parameter data  Receive & handle response from server  How do we do this?  JavaScript Jon Tedesco 12
  • 13. JavaScript Key features & use with AJAX Jon Tedesco 13
  • 14. JavaScript: Introduction  Runs on user’s browser  Place in <script> … </script>  Run on page load  Basic language properties  Interpreted  Single-threaded Jon Tedesco 14
  • 15. JavaScript: Basics  Language  Basic, readable syntax  Automatic type casting  Arrays, dictionaries  Development  Console Demo Jon Tedesco 15
  • 16. JavaScript: Functions  Functions  First-class citizens  Associated with scope  Callbacks  JavaScript is built for asynchronous programming! Jon Tedesco 16
  • 18. JavaScript: AJAX Example  Trigger JavaScript  On page load  On user event  On a timer  …  Submit HTTP request  Handle server response  Callbacks Jon Tedesco 18
  • 19. JavaScript: AJAX Example JavaScript (triggered by event) PHP (endpoint.php) Jon Tedesco 19
  • 20. jQuery Key features & use with AJAX Jon Tedesco 20
  • 21. jQuery: Motivation  JavaScript can be challenging  Too much code for simple tasks  Browser inconsistency  jQuery simplifies common tasks  DOM traversal & manipulation  Event handling  Animations  AJAX Jon Tedesco 21
  • 22. jQuery: Motivation  jQuery is …  Fast  Concise  Lightweight  Multi-browser compatible  Widely used  Over 55% of 10,000 most-visited sites  Over half of all websites Jon Tedesco 22
  • 23. jQuery: Basic Selectors Without jQuery With jQuery  DOM selection differs across browsers  Using jQuery, you can easily handle element selections  Hide/show  Animate  Modify content  … Jon Tedesco 23
  • 24. jQuery: DOM Manipulation & Animation Without jQuery With jQuery Jon Tedesco 24
  • 25. jQuery: AJAX Without jQuery With jQuery Jon Tedesco 25
  • 26. AJAX Demo  Let’s write the code…  PHP endpoint  Empty web page  Tools  jQuery  PHP  Google Chrome console Jon Tedesco 26
  • 27. AJAX Demo endpoint.php index.html Console / JavaScript Jon Tedesco 27
  • 28. AJAX Demo endpoint.php index.html Console / JavaScript Jon Tedesco 28
  • 29. Summary  Web Requests  GET &POST  AJAX Basics  JavaScript  Overview  Callbacks  AJAX  jQuery  Features  Demo Jon Tedesco 29
  • 31. References  GET v. POST  http://blog.teamtreehouse.com/the-definitive-guide-to-get-vs-post#disqus_thread  http://stackoverflow.com/questions/46585/when-do-you-use-post-and-when-do-you-use-get  http://www.jquery4u.com/ajax/key-differences-post/#.UIoD0Gl26QY  AJAX  http://scorebig.files.wordpress.com/2011/09/feed1.jpg  http://www.w3schools.com/ajax/ajax_intro.asp  JavaScript  http://en.wikipedia.org/wiki/JavaScript  jQuery  http://en.wikipedia.org/wiki/JQuery  http://www.sitepoint.com/jquery-used-on-50-percent-of-websites/  http://www.slideshare.net/arwid/jquery-4470993 Jon Tedesco 31

Editor's Notes

  1. // Declare a few varsvar foo = 5;var bar = &apos;abcde&apos;; // Automatic type castingvarfoobar = foo + bar; // Arrays &amp; dictionariesvarmyArray = [1,2,3];varmyDict = { &apos;key1&apos;: 1, &apos;key2&apos;: 2, &apos;key3&apos;: [1,2] };
  2. // Declare a few varsvar foo = 5;var bar = &apos;abcde&apos;; // Automatic type castingvarfoobar = foo + bar; // Arrays &amp; dictionariesvarmyArray = [1,2,3];varmyDict = { &apos;key1&apos;: 1, &apos;key2&apos;: 2, &apos;key3&apos;: [1,2] };
  3. // Function variablesvar equals = function(a, b) { return a == b; };varareEqual = equals(1, 2); // Anonymous function &amp; callbackvar a = 1;setTimeout(function() { a++; }, 5000);