SlideShare a Scribd company logo
1 of 11
JQuery AJAX
13/02/2023 1
Topics
• Overview of jQuery
• Installation and documentation
• Quick summary of jQuery selectors
• Data centric Ajax: the “$.ajax” function
– Basics
– Options
– Sending data
• Content-centric Ajax: the “load” function
• Handling JSON data
• Comparing Ajax support to other libraries
– Prototype, Dojo, Ext-JS
2
13/02/2023
Introduction
13/02/2023 3
Overview of jQuery
• Ajax utilities (this tutorial)
– General: $.ajax(…), $(…).load(…)
– Shortcuts: $.get, $.post, $.getJSON
• DOM search and manipulation utilities
– $("p.myStyle").addClass("extraStyle").show();
• Simple animation
– Not as extensive as Scriptaculous, but easy to use
• Cross-browser event model
– Assigns handlers programmatically, hides browser differences
• General JavaScript utilities
– Functions operating on strings and arrays
• Rich GUIs
– jQuery UI provides widgets, fancier effects, drag/drop
13/02/2023 4
Ajax Utilities
• $.ajax({options})
– Makes an Ajax request. Example:
• $.ajax({ url: "address", success:
responseHandler});
• The response handler is passed the response text, not the
response object. Don’t forget the “.” before “ajax”!
• load(url)
– Makes Ajax request and loads result into HTML element
• $("#some-id").load("address");
• A data string or object is an optional second arg
• Shortcuts
– $.get, $.post, $.getJSON
• Slightly simpler forms of $.ajax. However, as of jQuery 1.3,
they take data objects but not data strings, so you can’t use
“serialize”. So, $.ajax is better.
13/02/2023 5
Downloading and Installation
• Download
– http://docs.jquery.com/Downloading_jQuery
• Download single minimized file (e.g., jquery-1.3.2.min.js)
– Recommend renaming to jquery.js to simplify later upgrades
• Online API and tutorials
– http://docs.jquery.com/
• Browser Compatibility
– Firefox: 2 or later (vs. 1.5 or later for Prototype)
– Internet Explorer: 6 0 or later (does not work in IE 5 5) .0 or later
(does not work in IE 5.5)
– Safari: 3.0 or later (vs. 2.0 or later for Prototype)
– Opera: 9.0 or later (vs. 9.25 or later for Prototype)
– Chrome: 1.0 or later
– To check, run the test suite at http://jquery.com/test/
13/02/2023 6
Industry Usage
13/02/2023 7
jQuery Selectors
Basics
13/02/2023 8
Selecting DOM Elements
• Idea
– Use $("css selector") to get a set of DOM elements
• Then, perform operations on each
$("div.warning").html("Missing values!").show()
• Examples
– $("#some-id")
• Return 1-element set (or empty set) of element with id
• Simplest use, and most common for Ajax (note the “#”!)
– $("p")
• Return all p elements
– $(".blah")
• Return all elements that have class="blah"
– $("li b span.blah")
• Return all <span class="blah"> elements that are inside b
elements, that in turn are inside li elements
13/02/2023 9
Manipulating DOM Elements
• Common functions on matched elements
– $("#some-id").val()
• Returns value of input element. Used on 1-element sets.
– $("selector").each(function)
• Calls function on each element. “this” set to element.
– $("selector").addClass("name")
• Adds CSS class name to each. Also removeClass,
toggleClass
– $("selector").hide()
• Makes invisible (display: none). Also show, fadeOut, fadeIn,…
– $("selector").click(function)
• Adds onclick handler. Also change, focus, mouseover, …
– $("selector").html("<tag>some html</tag>")
• Sets the innerHTML of each element. Also append, prepend
• Chaining
– $("a").click(funct1).addClass("name").each(funct2)
13/02/2023 10
Example: Randomizing
Background Colors (JavaScript)
function randomizeHeadings() {
$("h3") each(setRandomStyle);
Call setRandomStyle function on each h3 element
.
$("h3.green").hide("slow");
} Slowly hide every h3 that has CSS style “green”
function setRandomStyle() {
$(this).addClass(randomStyle());
}
function randomStyle() {
var styles = ["red", "yellow", "green"];
Add “red”, “yellow” or “green” CSS names to each
return(randomElement(styles));
}
function randomElement( y) { array) {
var index = Math.floor(Math.random()*array.length);
return(array[index]);
}
13/02/2023 11

More Related Content

Similar to 2a-JQuery AJAX.pptx

jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
JavaScript!
JavaScript!JavaScript!
JavaScript!RTigger
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
A to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java DeveloperA to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java DeveloperManoj Bhuva
 
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
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tipsJack Franklin
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuerykolkatageeks
 
9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12Terry Yoast
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajaxbaygross
 
jQuery Learning
jQuery LearningjQuery Learning
jQuery LearningUzair Ali
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Libraryrsnarayanan
 
jQuery basics for Beginners
jQuery basics for BeginnersjQuery basics for Beginners
jQuery basics for BeginnersPooja Saxena
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQueryRemy Sharp
 

Similar to 2a-JQuery AJAX.pptx (20)

jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
J query
J queryJ query
J query
 
JavaScript!
JavaScript!JavaScript!
JavaScript!
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
A to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java DeveloperA to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java Developer
 
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
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tips
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
Jquery
JqueryJquery
Jquery
 
Jqueryppt (1)
Jqueryppt (1)Jqueryppt (1)
Jqueryppt (1)
 
9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12
 
Jquery
JqueryJquery
Jquery
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
jQuery Learning
jQuery LearningjQuery Learning
jQuery Learning
 
jQuery
jQueryjQuery
jQuery
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
 
jQuery basics for Beginners
jQuery basics for BeginnersjQuery basics for Beginners
jQuery basics for Beginners
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 

Recently uploaded

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 

2a-JQuery AJAX.pptx

  • 2. Topics • Overview of jQuery • Installation and documentation • Quick summary of jQuery selectors • Data centric Ajax: the “$.ajax” function – Basics – Options – Sending data • Content-centric Ajax: the “load” function • Handling JSON data • Comparing Ajax support to other libraries – Prototype, Dojo, Ext-JS 2 13/02/2023
  • 4. Overview of jQuery • Ajax utilities (this tutorial) – General: $.ajax(…), $(…).load(…) – Shortcuts: $.get, $.post, $.getJSON • DOM search and manipulation utilities – $("p.myStyle").addClass("extraStyle").show(); • Simple animation – Not as extensive as Scriptaculous, but easy to use • Cross-browser event model – Assigns handlers programmatically, hides browser differences • General JavaScript utilities – Functions operating on strings and arrays • Rich GUIs – jQuery UI provides widgets, fancier effects, drag/drop 13/02/2023 4
  • 5. Ajax Utilities • $.ajax({options}) – Makes an Ajax request. Example: • $.ajax({ url: "address", success: responseHandler}); • The response handler is passed the response text, not the response object. Don’t forget the “.” before “ajax”! • load(url) – Makes Ajax request and loads result into HTML element • $("#some-id").load("address"); • A data string or object is an optional second arg • Shortcuts – $.get, $.post, $.getJSON • Slightly simpler forms of $.ajax. However, as of jQuery 1.3, they take data objects but not data strings, so you can’t use “serialize”. So, $.ajax is better. 13/02/2023 5
  • 6. Downloading and Installation • Download – http://docs.jquery.com/Downloading_jQuery • Download single minimized file (e.g., jquery-1.3.2.min.js) – Recommend renaming to jquery.js to simplify later upgrades • Online API and tutorials – http://docs.jquery.com/ • Browser Compatibility – Firefox: 2 or later (vs. 1.5 or later for Prototype) – Internet Explorer: 6 0 or later (does not work in IE 5 5) .0 or later (does not work in IE 5.5) – Safari: 3.0 or later (vs. 2.0 or later for Prototype) – Opera: 9.0 or later (vs. 9.25 or later for Prototype) – Chrome: 1.0 or later – To check, run the test suite at http://jquery.com/test/ 13/02/2023 6
  • 9. Selecting DOM Elements • Idea – Use $("css selector") to get a set of DOM elements • Then, perform operations on each $("div.warning").html("Missing values!").show() • Examples – $("#some-id") • Return 1-element set (or empty set) of element with id • Simplest use, and most common for Ajax (note the “#”!) – $("p") • Return all p elements – $(".blah") • Return all elements that have class="blah" – $("li b span.blah") • Return all <span class="blah"> elements that are inside b elements, that in turn are inside li elements 13/02/2023 9
  • 10. Manipulating DOM Elements • Common functions on matched elements – $("#some-id").val() • Returns value of input element. Used on 1-element sets. – $("selector").each(function) • Calls function on each element. “this” set to element. – $("selector").addClass("name") • Adds CSS class name to each. Also removeClass, toggleClass – $("selector").hide() • Makes invisible (display: none). Also show, fadeOut, fadeIn,… – $("selector").click(function) • Adds onclick handler. Also change, focus, mouseover, … – $("selector").html("<tag>some html</tag>") • Sets the innerHTML of each element. Also append, prepend • Chaining – $("a").click(funct1).addClass("name").each(funct2) 13/02/2023 10
  • 11. Example: Randomizing Background Colors (JavaScript) function randomizeHeadings() { $("h3") each(setRandomStyle); Call setRandomStyle function on each h3 element . $("h3.green").hide("slow"); } Slowly hide every h3 that has CSS style “green” function setRandomStyle() { $(this).addClass(randomStyle()); } function randomStyle() { var styles = ["red", "yellow", "green"]; Add “red”, “yellow” or “green” CSS names to each return(randomElement(styles)); } function randomElement( y) { array) { var index = Math.floor(Math.random()*array.length); return(array[index]); } 13/02/2023 11