SlideShare a Scribd company logo
1 of 33
LESSON FOUR
    jQuery intro
Fast Review
Functions = “First Class Objects”
Anonymous Functions

     function() {
      // code goes here
      }
Arrays


data structure for ordered values
   var team = [‘ben’,‘jeff’,‘kam’];
   team[0] // => ‘ben’
Objects



collections of “key/value” properties
  var person = {};
  person.name = ‘will’;    // Write
  var name = person.name; // Read
Document Object Model
Review Homework
Enter, jQuery
What is jQuery

Framework for using Javascript to interact with
the browser
•   Simple DOM API: manipulate HTML / CSS on the page

•   Simple AJAX API: send and receive data from the server

•   Simple Event API: do stuff when the user does stuff

•   Thats it!
What is a Framework?

                    A library of utility functions

Small                  Medium                   Large
•   Underscore.js       •   jQuery UI       •    YUI (Yahoo UI)
•   jQuery              •   MooTools        •    GWT (Google web toolkit)
•   Prototype.js        •   Dojo            •    EXT JS (commercial)



      there are LOTS of them for web development
Why use jQuery
•   The DOM API is _nasty_!

•   Cross browser

•   Fast - Faster than raw DOM manipulation! *magic*

•   Lightweight (31kb)

•   Stable and trusted

•   Required for many other frameworks

•   EVERYBODY uses it
Include jQuery
<script src="/js/jquery.js"></script>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/
jquery.min.js"></script>



                         Try it out!
jQuery Syntax
  or…how to follow the $

$(document).ready(function(){
  // Your code here
});




    DOM Manipulation
   $("a").addClass("test");
using jQuery
Selecting Elements
                      Using CSS!


$("#foo")     // the [element] at id “foo”


$(".bloop")   // the [elements] with class “bloop”


$("a.buzz")   // the [links] with class ‘buzz’



$(".bloop:first")      // specialty! The first bloop!


=>   :hidden, :visible, :last, :checked, :empty,       :odd...
Important Methods
.show() / .hide() / .toggle()
   $(".swap_text").toggle();


.addClass(".active")
.removeClass(".active")


.css(key, value)
   $("#my_box").css(‘backgroundColor’,   ‘red’);
   $("#my_box").css({

            ‘backgroundColor’ : ‘red’,
            ‘color’ : ‘#030’
   });
Important Methods

.animate(properties, duration, callback)

   $(‘#my_box’).animate({
            ‘backgroundColor’ : ‘red’,
            ‘marginTop‘         : ‘20px’,
            ‘color‘             : ‘#030’
   }, 3000, justFinished);   // execute the animation for 3 seconds
                             // and when done, call: justFinished();
Important Methods

.html() / .val() / .attr(‘attribute’)

   $(‘#my_title’).html(); // returns the innerHTML

   $(‘#my_title’).html(“New Title!”); // sets the innerHTML



   $(‘input#email’).val(“please enter your email address...”);



   $(‘img’).attr(“src”, “placekitten.com/30/30”);



                             as before: these methods can get or set...
Methods Can “Chain”




$("#my_box").addClass(‘inactive’).removeClass(‘active’).hide();
jQuery Events

$(document).ready()     // the DOM is loaded
window.load()           // all elements (including images)
                           have loaded


.change()
.submit()
.focus()
.click
.scroll()
.hover()
.keypress()                                ...And so many more!
Events w/o jQuery
                      no browser consistency




EX:


.addEventListener("click", function({}) );   // Firefox


.attachEvent("onclick", function({}) );      // Internet Explorer
jQuery Insertion




.append()
.after()
.insertAfter()
.before
.insertBefore()
.clone()
Client Side
   Requests
[XHR and AJAX]
XMLHttpRequest




Allows you to make a web request via client side javascript
Invented by Microsoft for Internet Explorer, then ported to other
browsers

   var request = new XMLHttpRequest(); // Create new request object
   request.open(“GET”, “path/file.ext”, false); // “open” the request
   request.send(null); // Make the request
   var text = request.responseText; // Check the response text
BUZZZZWORD




“XHR”
•   XMLHttpRequest

•   Misnomer => Not limited to XML data

•   By default, synchronous
AJAX




By default, XHR proceeds synchronously
In other words, your code will hang until the request is complete
What if you want your code to keep executing?
   => Use AJAX
BUZZZZWORD



“AJAX”
•   “Asynchronous Javascript and XML”

•   XHR done asynchronously

•   Provide a callback to execute when the request is complete

•   Changed the face of web development => page reloads no longer
    required to add new content to a page
AJAX via DOM



var request = new XMLHttpRequest(); // Create new request object
request.open(“GET”, “path/file.ext”, true); // ‘True’ => AJAX

request.send(null); // Make the request
var text = request.responseText; // Will be null this time!
request.onreadystatechange = function() {
 if (request.readyState == 4) {
     // Request is done. Can check responseText
 }
AJAX via DOM



var request = new XMLHttpRequest(); // Create new request object
request.open(“GET”, “path/file.ext”, true); // ‘True’ => AJAX


          CONFUSING this time!
request.send(null); // Make the request
var text = request.responseText; // Will be null
request.onreadystatechange = function() {
 if (request.readyState == 4) {
     // Request is done. Can check responseText
 }
AJAX via jQuery



    $.ajax({
  url: "test.html",
  success: function(return_text){
    $("#results").append(return_text);
 }
});




                          more next week...
QUESTIONS?
contact will_and_bay@hackyale.com

More Related Content

What's hot

jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoiddmethvin
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuerySudar Muthu
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuerymanugoel2003
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practicesbrinsknaps
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery PresentationRod Johnson
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperJon Kruger
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptJon Kruger
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery EssentialsMark Rackley
 
Don't Worry jQuery is very Easy:Learning Tips For jQuery
Don't Worry jQuery is very Easy:Learning Tips For jQueryDon't Worry jQuery is very Easy:Learning Tips For jQuery
Don't Worry jQuery is very Easy:Learning Tips For jQueryshabab shihan
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryZeeshan Khan
 

What's hot (20)

jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
jQuery
jQueryjQuery
jQuery
 
jQuery
jQueryjQuery
jQuery
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practices
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScript
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
 
Don't Worry jQuery is very Easy:Learning Tips For jQuery
Don't Worry jQuery is very Easy:Learning Tips For jQueryDon't Worry jQuery is very Easy:Learning Tips For jQuery
Don't Worry jQuery is very Easy:Learning Tips For jQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 

Viewers also liked

Metodología de Investigación "Comunicative Daile Life Stories"
Metodología de Investigación "Comunicative Daile Life Stories"Metodología de Investigación "Comunicative Daile Life Stories"
Metodología de Investigación "Comunicative Daile Life Stories"Vanessa Costa
 
Application 1785686
Application 1785686Application 1785686
Application 1785686Vishal Shah
 
2007 bpc conference
2007 bpc conference2007 bpc conference
2007 bpc conferenceguest56b4f0
 
Lives of the Great War: Building First World War life stories across archives...
Lives of the Great War: Building First World War life stories across archives...Lives of the Great War: Building First World War life stories across archives...
Lives of the Great War: Building First World War life stories across archives...Museums Computer Group
 
State of the LexBlog Address 2016 - Slides from LexBlog's Webinar
State of the LexBlog Address 2016 - Slides from LexBlog's WebinarState of the LexBlog Address 2016 - Slides from LexBlog's Webinar
State of the LexBlog Address 2016 - Slides from LexBlog's WebinarLexBlog, Inc.
 

Viewers also liked (6)

Metodología de Investigación "Comunicative Daile Life Stories"
Metodología de Investigación "Comunicative Daile Life Stories"Metodología de Investigación "Comunicative Daile Life Stories"
Metodología de Investigación "Comunicative Daile Life Stories"
 
Application 1785686
Application 1785686Application 1785686
Application 1785686
 
2007 bpc conference
2007 bpc conference2007 bpc conference
2007 bpc conference
 
Lives of the Great War: Building First World War life stories across archives...
Lives of the Great War: Building First World War life stories across archives...Lives of the Great War: Building First World War life stories across archives...
Lives of the Great War: Building First World War life stories across archives...
 
Alexis Willey
Alexis Willey Alexis Willey
Alexis Willey
 
State of the LexBlog Address 2016 - Slides from LexBlog's Webinar
State of the LexBlog Address 2016 - Slides from LexBlog's WebinarState of the LexBlog Address 2016 - Slides from LexBlog's Webinar
State of the LexBlog Address 2016 - Slides from LexBlog's Webinar
 

Similar to Week 4 - jQuery + Ajax

A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETJames Johnson
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETJames Johnson
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsEPAM Systems
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyHuiyi Yan
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksHjörtur Hilmarsson
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 

Similar to Week 4 - jQuery + Ajax (20)

A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NET
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
jQuery
jQueryjQuery
jQuery
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
JavaScript JQUERY AJAX
JavaScript JQUERY AJAXJavaScript JQUERY AJAX
JavaScript JQUERY AJAX
 
J query training
J query trainingJ query training
J query training
 
jQuery for web development
jQuery for web developmentjQuery for web development
jQuery for web development
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
22 j query1
22 j query122 j query1
22 j query1
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 

Recently uploaded

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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
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
 

Recently uploaded (20)

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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
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
 
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
 

Week 4 - jQuery + Ajax

  • 1.
  • 2. LESSON FOUR jQuery intro
  • 4. Functions = “First Class Objects”
  • 5. Anonymous Functions function() { // code goes here }
  • 6. Arrays data structure for ordered values var team = [‘ben’,‘jeff’,‘kam’]; team[0] // => ‘ben’
  • 7. Objects collections of “key/value” properties var person = {}; person.name = ‘will’; // Write var name = person.name; // Read
  • 11. What is jQuery Framework for using Javascript to interact with the browser • Simple DOM API: manipulate HTML / CSS on the page • Simple AJAX API: send and receive data from the server • Simple Event API: do stuff when the user does stuff • Thats it!
  • 12. What is a Framework? A library of utility functions Small Medium Large • Underscore.js • jQuery UI • YUI (Yahoo UI) • jQuery • MooTools • GWT (Google web toolkit) • Prototype.js • Dojo • EXT JS (commercial) there are LOTS of them for web development
  • 13. Why use jQuery • The DOM API is _nasty_! • Cross browser • Fast - Faster than raw DOM manipulation! *magic* • Lightweight (31kb) • Stable and trusted • Required for many other frameworks • EVERYBODY uses it
  • 14. Include jQuery <script src="/js/jquery.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/ jquery.min.js"></script> Try it out!
  • 15. jQuery Syntax or…how to follow the $ $(document).ready(function(){ // Your code here }); DOM Manipulation $("a").addClass("test");
  • 17. Selecting Elements Using CSS! $("#foo") // the [element] at id “foo” $(".bloop") // the [elements] with class “bloop” $("a.buzz") // the [links] with class ‘buzz’ $(".bloop:first") // specialty! The first bloop! => :hidden, :visible, :last, :checked, :empty, :odd...
  • 18. Important Methods .show() / .hide() / .toggle() $(".swap_text").toggle(); .addClass(".active") .removeClass(".active") .css(key, value) $("#my_box").css(‘backgroundColor’, ‘red’); $("#my_box").css({ ‘backgroundColor’ : ‘red’, ‘color’ : ‘#030’ });
  • 19. Important Methods .animate(properties, duration, callback) $(‘#my_box’).animate({ ‘backgroundColor’ : ‘red’, ‘marginTop‘ : ‘20px’, ‘color‘ : ‘#030’ }, 3000, justFinished); // execute the animation for 3 seconds // and when done, call: justFinished();
  • 20. Important Methods .html() / .val() / .attr(‘attribute’) $(‘#my_title’).html(); // returns the innerHTML $(‘#my_title’).html(“New Title!”); // sets the innerHTML $(‘input#email’).val(“please enter your email address...”); $(‘img’).attr(“src”, “placekitten.com/30/30”); as before: these methods can get or set...
  • 22. jQuery Events $(document).ready() // the DOM is loaded window.load() // all elements (including images) have loaded .change() .submit() .focus() .click .scroll() .hover() .keypress() ...And so many more!
  • 23. Events w/o jQuery no browser consistency EX: .addEventListener("click", function({}) ); // Firefox .attachEvent("onclick", function({}) ); // Internet Explorer
  • 25. Client Side Requests [XHR and AJAX]
  • 26. XMLHttpRequest Allows you to make a web request via client side javascript Invented by Microsoft for Internet Explorer, then ported to other browsers var request = new XMLHttpRequest(); // Create new request object request.open(“GET”, “path/file.ext”, false); // “open” the request request.send(null); // Make the request var text = request.responseText; // Check the response text
  • 27. BUZZZZWORD “XHR” • XMLHttpRequest • Misnomer => Not limited to XML data • By default, synchronous
  • 28. AJAX By default, XHR proceeds synchronously In other words, your code will hang until the request is complete What if you want your code to keep executing? => Use AJAX
  • 29. BUZZZZWORD “AJAX” • “Asynchronous Javascript and XML” • XHR done asynchronously • Provide a callback to execute when the request is complete • Changed the face of web development => page reloads no longer required to add new content to a page
  • 30. AJAX via DOM var request = new XMLHttpRequest(); // Create new request object request.open(“GET”, “path/file.ext”, true); // ‘True’ => AJAX request.send(null); // Make the request var text = request.responseText; // Will be null this time! request.onreadystatechange = function() { if (request.readyState == 4) { // Request is done. Can check responseText }
  • 31. AJAX via DOM var request = new XMLHttpRequest(); // Create new request object request.open(“GET”, “path/file.ext”, true); // ‘True’ => AJAX CONFUSING this time! request.send(null); // Make the request var text = request.responseText; // Will be null request.onreadystatechange = function() { if (request.readyState == 4) { // Request is done. Can check responseText }
  • 32. AJAX via jQuery $.ajax({   url: "test.html",   success: function(return_text){     $("#results").append(return_text);  } }); more next week...

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n