SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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.
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 

Último (20)

React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 

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...

Notas do Editor

  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