SlideShare a Scribd company logo
JavaScript Essentials
               JQuery & AJAX
                                  Mak Bhatamrekar
                   http://github.com/makrand-bkar

                                             AJCP




http://meetup.com/my-ajcp
Atlanta Java Concept Pros
JQuery Features
Feature                     Desc

AJAX                        $.ajax(..), $.getJSON(..), $.get(..),$.post(), $.load()
                            $.ajax({url:”address”,success: “handler”}); (Base
                            method)
                            $(“#myid”).load(“address”) - loads HTML Element
DOM Manipulation / Search    $(“p.myStyle”).addClass(“BoldStyle”).show(). Easy to
                            find siblings, children, closest, nth element.


Animations / Effects        fade, show, hide,more..

Externalized Events         Events are binding happens in JS and not in html

Cross Browser Support       Supports all Major Browsers IE(>6.0), FF, Safari,Chrome

Jquery UI & Plugins         Widgets, and lots of Plugins
Why JQuery
DOM Selection
  • Uses familiar CSS Selector to find Elements.
  • CSS Selector reads from Right to Left (11.htm)
Selector                  Desc
$(“#myId”)                Selects Element with a particular ID (only one)
$(“h1”)                   Returns all the h1 elements
$(“.myClass”)             Returns all the elements that have class “myClass”
$(“headerDiv h1           Return all (span= “myClass”) elements which are inside h1 and
span.myClass”)            inturn which are inside headerDiv.
                          1.grossly formed selectors will Slower performance, good idea to
                          add a Class to Element for faster Selection
                          2.Cache the Selector in a variable if used frequently.
                               var mySel = $(“headerDiv h1 span.myclass”);
$(‘input[value=“foo”]’)   Returns the input elem whose value is foo
DOM Functions
$(“#txBox”).val() / $(“#txBox”).val(“nval”) Get or Set value of elem.e.g
                                            TxBox,Input,Button
$(“#elem”).html()/$(“#elem”).html(..)         Get or Set html of elem e.g div,p etc
$(“#e”).siblings(), .children(), .closest()   Traversing to the right Element
$(“#elem”).click(function)                    Adds click handler. Some others focus,
                                              mouseover, change
$.each(obj,function(idx,val){..});            Utilities - Iterate over each object in the
                                              elem or object.
$.trim(“obj”)                                 Utitlies – trims
$.data()                                      attaches custom data


JQuery Chaining –
$("#p1").css("color","red").slideUp(2000).slideDown(2000);
Restful AJAX – X stands for JSON
Async JavaScript and XML. Fetch data from Server Asynchronously
Advantages         • Interactive and Desktop Feel
                   • Refreshes only Data instead of Entire Page
                   • Create Server less Clients, with Cloud and Services.

Dis-Advantages     • Loose Context Browser History Fwd and Back Button
                   • JavaScript has to be enabled

REST Based Calls   GET – Fetch Records               UPDATE – Update Record
(HTTP Verbs)       POST – Create Record              DELETE – Delete record
Jquery AJAX Functions.
$.ajax{url:”addr”, success: handler,      • Base Method
inputdata })                              • Inputdata can be
                                            -- String (url encoding TBD)
function handler(data,httpStatus,req)       -- JSON literal
                                          • Other Options

$.post(), $.get()                         • Convenience /Shorthand Method for AJAX
                                            tailored to request
$.post(“addr”,success:function)           • It also supports chaining from Jquery 1.5
$.get(“addr”).success(function).error()   • $.ajax({type:”post”,options})

$(“#result”).load(url,completeFunc)       • Loads a specific page or part of the page
                                          • Internall calls $.get

$.getJSON()                               • Load JSON-encoded data from the server
                                             using a GET HTTP request.
                                          $.ajax({dataType: "json“,options})
JSONP(JSON Padding)

PROBLEM
Same origin policy of browser prevents a script loaded from one domain to make ajax
calls on another domain.
JSONP Solution - Return a JSON Object wrapped in a requested Call back. This Script
is injected on Window Object, executed .
Steps
Step1 – Ajax call is made with callback param http://query.yahooapis.com/v1?
format=json&callback=cbfunc

Step2: servers responds as cbfunc(JSON String)

Step3: Browser treats the response as a script, downloads and executes the script.
Deferred Object
• Enables to work with values that may not be immediately present like AJAX calls.
• Its like Publish/Subscribe, which allows you to perform logic when say couple of
  AJAX request are finished.
• Allows to Wait on multiple AJAX Requests
• Ability to attach Multiple Event Handlers

//Step1 : dfd = $.deferred() -- Create $.deferred() object
//Step2 : function myfunc(){ --
  if ( success) dfd.resolve() //Once function is done invoke resolve()
  else
   dfd.reject() //if failed invoke reject(), so that deferred can invoke reject stack
  return dfd.promise() //return the promise
}
//Step3 : add handlers
dfd.done() -- when call is success
dfd.fail() -- when call is failed
dfd.always – always call
Appendix
• Source code can be found on github

  – https://github.com/makrand-bkar/ajip_javascript
  – (11-*.html and 12-*.html)
  – https://github.com/makrand-bkar/RestServer
    (download the war file from /downloads)
Questions
• Why Jquery ?
• DOM Manipulations Questions
• How to Invoke Ajax()
THANK YOU

More Related Content

What's hot (20)

PDF
Spring Data JPA
Knoldus Inc.
 
PPTX
Java Server Pages(jsp)
Manisha Keim
 
PDF
Hibernate Presentation
guest11106b
 
PPTX
Java - Collections framework
Riccardo Cardin
 
PDF
Introduction to Spring's Dependency Injection
Richard Paul
 
PDF
Reactjs Basics
Hamid Ghorbani
 
PDF
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Edureka!
 
PPT
Core java concepts
Ram132
 
PPTX
Java 8 presentation
Van Huong
 
PPT
Node.js Express Framework
TheCreativedev Blog
 
PPTX
JavaFX Presentation
Mochamad Taufik Mulyadi
 
PPTX
Spring Boot and REST API
07.pallav
 
PPTX
Spring boot
Pradeep Shanmugam
 
PDF
Java11 New Features
Haim Michael
 
PPTX
Introduction to Operational Semantics
jsinglet
 
PPTX
Document Object Model (DOM)
GOPAL BASAK
 
PPT
JDBC – Java Database Connectivity
Information Technology
 
PDF
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
PPTX
Spring boot
sdeeg
 
Spring Data JPA
Knoldus Inc.
 
Java Server Pages(jsp)
Manisha Keim
 
Hibernate Presentation
guest11106b
 
Java - Collections framework
Riccardo Cardin
 
Introduction to Spring's Dependency Injection
Richard Paul
 
Reactjs Basics
Hamid Ghorbani
 
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Edureka!
 
Core java concepts
Ram132
 
Java 8 presentation
Van Huong
 
Node.js Express Framework
TheCreativedev Blog
 
JavaFX Presentation
Mochamad Taufik Mulyadi
 
Spring Boot and REST API
07.pallav
 
Spring boot
Pradeep Shanmugam
 
Java11 New Features
Haim Michael
 
Introduction to Operational Semantics
jsinglet
 
Document Object Model (DOM)
GOPAL BASAK
 
JDBC – Java Database Connectivity
Information Technology
 
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
Spring boot
sdeeg
 

Viewers also liked (16)

DOCX
Jquery Ajax
Anand Kumar Rajana
 
PPT
jQuery Ajax
Anand Kumar Rajana
 
PPTX
CSS Fundamentals: selectors and Properties
Pedro Valente
 
PPTX
Ajax and Jquery
People Strategists
 
PDF
Javascript ajax tutorial
Vlad Posea
 
PPTX
Understanding Javascript AJAX - Imrokraft
imrokraft
 
PDF
CSS3, Media Queries, and Responsive Design
Zoe Gillenwater
 
PDF
Javascript & Ajax Basics
Richard Paul
 
PDF
CSS3 Media Queries
Russ Weakley
 
PPT
An Introduction to Ajax Programming
hchen1
 
PPT
Ajax Ppt
Hema Prasanth
 
PDF
Introduction to ajax
Nir Elbaz
 
PPTX
JSON: The Basics
Jeff Fox
 
PPTX
Ajax ppt - 32 slides
Smithss25
 
PDF
Introduction to Bootstrap
Ron Reiter
 
PPTX
Introduction to ajax
Raja V
 
Jquery Ajax
Anand Kumar Rajana
 
jQuery Ajax
Anand Kumar Rajana
 
CSS Fundamentals: selectors and Properties
Pedro Valente
 
Ajax and Jquery
People Strategists
 
Javascript ajax tutorial
Vlad Posea
 
Understanding Javascript AJAX - Imrokraft
imrokraft
 
CSS3, Media Queries, and Responsive Design
Zoe Gillenwater
 
Javascript & Ajax Basics
Richard Paul
 
CSS3 Media Queries
Russ Weakley
 
An Introduction to Ajax Programming
hchen1
 
Ajax Ppt
Hema Prasanth
 
Introduction to ajax
Nir Elbaz
 
JSON: The Basics
Jeff Fox
 
Ajax ppt - 32 slides
Smithss25
 
Introduction to Bootstrap
Ron Reiter
 
Introduction to ajax
Raja V
 
Ad

Similar to JavaScript JQUERY AJAX (20)

PDF
jQuery
Ivano Malavolta
 
PPT
Jquery 4
Manish Kumar Singh
 
PPTX
Ajax
Nibin Manuel
 
PDF
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
PPT
jQuery for beginners
Divakar Gu
 
PPTX
2a-JQuery AJAX.pptx
Le Hung
 
PPTX
A Rich Web experience with jQuery, Ajax and .NET
James Johnson
 
PPT
J Query Public
pradeepsilamkoti
 
KEY
Week 4 - jQuery + Ajax
baygross
 
PPTX
Introduction to Jquery
Ahmed Elharouny
 
PDF
Remy Sharp The DOM scripting toolkit jQuery
deimos
 
PPTX
A Rich Web Experience with jQuery, Ajax and .NET
James Johnson
 
PPTX
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
David Giard
 
PDF
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Sean Burgess
 
PDF
DOM Scripting Toolkit - jQuery
Remy Sharp
 
PPT
J query b_dotnet_ug_meet_12_may_2012
ghnash
 
PDF
jQuery Interview Questions By ScholarHat.pdf
Scholarhat
 
PPT
jQuery Fundamentals
Doncho Minkov
 
PDF
Intro to jQuery @ Startup Institute
Rafael Gonzaque
 
PPTX
Web Development Introduction to jQuery
Laurence Svekis ✔
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
jQuery for beginners
Divakar Gu
 
2a-JQuery AJAX.pptx
Le Hung
 
A Rich Web experience with jQuery, Ajax and .NET
James Johnson
 
J Query Public
pradeepsilamkoti
 
Week 4 - jQuery + Ajax
baygross
 
Introduction to Jquery
Ahmed Elharouny
 
Remy Sharp The DOM scripting toolkit jQuery
deimos
 
A Rich Web Experience with jQuery, Ajax and .NET
James Johnson
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
David Giard
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Sean Burgess
 
DOM Scripting Toolkit - jQuery
Remy Sharp
 
J query b_dotnet_ug_meet_12_may_2012
ghnash
 
jQuery Interview Questions By ScholarHat.pdf
Scholarhat
 
jQuery Fundamentals
Doncho Minkov
 
Intro to jQuery @ Startup Institute
Rafael Gonzaque
 
Web Development Introduction to jQuery
Laurence Svekis ✔
 
Ad

More from Makarand Bhatambarekar (8)

PPT
Bootstrapping angular js with bower grunt yeoman
Makarand Bhatambarekar
 
PPTX
Sprintintegration ajip
Makarand Bhatambarekar
 
PPTX
Sonarjenkins ajip
Makarand Bhatambarekar
 
PPT
Springaopdecoded ajip
Makarand Bhatambarekar
 
PPT
Story ofcorespring infodeck
Makarand Bhatambarekar
 
PPTX
Java scriptforjavadev part1
Makarand Bhatambarekar
 
PPTX
Java scriptforjavadev part2a
Makarand Bhatambarekar
 
PPTX
Getting Started with J2EE, A Roadmap
Makarand Bhatambarekar
 
Bootstrapping angular js with bower grunt yeoman
Makarand Bhatambarekar
 
Sprintintegration ajip
Makarand Bhatambarekar
 
Sonarjenkins ajip
Makarand Bhatambarekar
 
Springaopdecoded ajip
Makarand Bhatambarekar
 
Story ofcorespring infodeck
Makarand Bhatambarekar
 
Java scriptforjavadev part1
Makarand Bhatambarekar
 
Java scriptforjavadev part2a
Makarand Bhatambarekar
 
Getting Started with J2EE, A Roadmap
Makarand Bhatambarekar
 

Recently uploaded (20)

PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 

JavaScript JQUERY AJAX

  • 1. JavaScript Essentials JQuery & AJAX Mak Bhatamrekar http://github.com/makrand-bkar AJCP http://meetup.com/my-ajcp Atlanta Java Concept Pros
  • 2. JQuery Features Feature Desc AJAX $.ajax(..), $.getJSON(..), $.get(..),$.post(), $.load() $.ajax({url:”address”,success: “handler”}); (Base method) $(“#myid”).load(“address”) - loads HTML Element DOM Manipulation / Search $(“p.myStyle”).addClass(“BoldStyle”).show(). Easy to find siblings, children, closest, nth element. Animations / Effects fade, show, hide,more.. Externalized Events Events are binding happens in JS and not in html Cross Browser Support Supports all Major Browsers IE(>6.0), FF, Safari,Chrome Jquery UI & Plugins Widgets, and lots of Plugins
  • 4. DOM Selection • Uses familiar CSS Selector to find Elements. • CSS Selector reads from Right to Left (11.htm) Selector Desc $(“#myId”) Selects Element with a particular ID (only one) $(“h1”) Returns all the h1 elements $(“.myClass”) Returns all the elements that have class “myClass” $(“headerDiv h1 Return all (span= “myClass”) elements which are inside h1 and span.myClass”) inturn which are inside headerDiv. 1.grossly formed selectors will Slower performance, good idea to add a Class to Element for faster Selection 2.Cache the Selector in a variable if used frequently. var mySel = $(“headerDiv h1 span.myclass”); $(‘input[value=“foo”]’) Returns the input elem whose value is foo
  • 5. DOM Functions $(“#txBox”).val() / $(“#txBox”).val(“nval”) Get or Set value of elem.e.g TxBox,Input,Button $(“#elem”).html()/$(“#elem”).html(..) Get or Set html of elem e.g div,p etc $(“#e”).siblings(), .children(), .closest() Traversing to the right Element $(“#elem”).click(function) Adds click handler. Some others focus, mouseover, change $.each(obj,function(idx,val){..}); Utilities - Iterate over each object in the elem or object. $.trim(“obj”) Utitlies – trims $.data() attaches custom data JQuery Chaining – $("#p1").css("color","red").slideUp(2000).slideDown(2000);
  • 6. Restful AJAX – X stands for JSON Async JavaScript and XML. Fetch data from Server Asynchronously Advantages • Interactive and Desktop Feel • Refreshes only Data instead of Entire Page • Create Server less Clients, with Cloud and Services. Dis-Advantages • Loose Context Browser History Fwd and Back Button • JavaScript has to be enabled REST Based Calls GET – Fetch Records UPDATE – Update Record (HTTP Verbs) POST – Create Record DELETE – Delete record
  • 7. Jquery AJAX Functions. $.ajax{url:”addr”, success: handler, • Base Method inputdata }) • Inputdata can be -- String (url encoding TBD) function handler(data,httpStatus,req) -- JSON literal • Other Options $.post(), $.get() • Convenience /Shorthand Method for AJAX tailored to request $.post(“addr”,success:function) • It also supports chaining from Jquery 1.5 $.get(“addr”).success(function).error() • $.ajax({type:”post”,options}) $(“#result”).load(url,completeFunc) • Loads a specific page or part of the page • Internall calls $.get $.getJSON() • Load JSON-encoded data from the server using a GET HTTP request. $.ajax({dataType: "json“,options})
  • 8. JSONP(JSON Padding) PROBLEM Same origin policy of browser prevents a script loaded from one domain to make ajax calls on another domain. JSONP Solution - Return a JSON Object wrapped in a requested Call back. This Script is injected on Window Object, executed . Steps Step1 – Ajax call is made with callback param http://query.yahooapis.com/v1? format=json&callback=cbfunc Step2: servers responds as cbfunc(JSON String) Step3: Browser treats the response as a script, downloads and executes the script.
  • 9. Deferred Object • Enables to work with values that may not be immediately present like AJAX calls. • Its like Publish/Subscribe, which allows you to perform logic when say couple of AJAX request are finished. • Allows to Wait on multiple AJAX Requests • Ability to attach Multiple Event Handlers //Step1 : dfd = $.deferred() -- Create $.deferred() object //Step2 : function myfunc(){ -- if ( success) dfd.resolve() //Once function is done invoke resolve() else dfd.reject() //if failed invoke reject(), so that deferred can invoke reject stack return dfd.promise() //return the promise } //Step3 : add handlers dfd.done() -- when call is success dfd.fail() -- when call is failed dfd.always – always call
  • 10. Appendix • Source code can be found on github – https://github.com/makrand-bkar/ajip_javascript – (11-*.html and 12-*.html) – https://github.com/makrand-bkar/RestServer (download the war file from /downloads)
  • 11. Questions • Why Jquery ? • DOM Manipulations Questions • How to Invoke Ajax()