SlideShare a Scribd company logo
1 of 27
Download to read offline
Introduction to AJAX
Nir Elbaz
IntroductiontoAJAX
Nir
Elbaz
Introduction to AJAX
• Index
• What is AJAX?
• MakingAJAX requests with raw JavaScript
• MakingAJAX requests with jQuery
• AJAX & ASP.net
• AJAX security
IntroductiontoAJAX
Nir
Elbaz
What is AJAX
• AJAX stands for Asynchronous JavaScript And XML
• Allows web pages or parts of them to be updated asynchronously
• Based on XML HTTP request object (AKA XHR)
• Requires basic understanding of:
• (X)HTML – displaying the data
• CSS – styling the data
• JavaScript – manipulating the DOM
• XML / JSON – received / sent data format (also HTML & text)
Also refers dynamic content
IntroductiontoAJAX
Nir
Elbaz
What is AJAX
Browser
User Interface
Web Server
Databases, backend
processes
HTTP(S)Transport
HTTP request
HTML/CSS/JS/* response
Classic web application model
Browser
User Interface
Web Server
Databases, backend
processes
HTTP(S)Transport
HTTP request
HTML/CSS/JS/* response
AJAX web application model
AJAX engine
JS call
Validresponsecanbeanytextualdata:html,css,js,csv,xml…
IntroductiontoAJAX
Nir
Elbaz
What is AJAX
Classic web application model AJAX web application model
User
Front end
Back end
IntroductiontoAJAX
Nir
Elbaz
What is AJAX
• Usage samples
• Autocomplete search textboxes (sample)
• Cascading dropdown list boxes (sample)
• Real-time - Continuous data refresh (long polling, chat systems…)
• Immediate forms validation feedback (sample)
• Conditional display / dynamic content (sample)
• Auto save user information (Google Docs, Facebook)
• Ratings, voting & other instant actions (sample)
IntroductiontoAJAX
Nir
Elbaz
What is AJAX
• Browser support
• Mozilla Firefox 1.0 and above
• Google Chrome
• Apple Safari 1.2 and above
• Microsoft Internet Exporer 5 and above (ActiveXObject for lte IE6)
• Opera 7.6 and above
IntroductiontoAJAX
Nir
Elbaz
What is AJAX
• Pros
• Better interactivity & responsiveness
• Impressive UX
• Reduced connections to the web server (partial rendering)
• Reduced bandwidth
• Its “cool” 
IntroductiontoAJAX
Nir
Elbaz
What is AJAX
• Cons
• The back and refresh button are rendered useless
• Bookmarking is useless (HTML 5 History API to the rescue)
• Requires JavaScript to be enabled on browsers
• SEO & analytics unfriendly
• Screen readers unfriendly – affects accessibility
• Callbacks can lead to complex code
• Network latency may break usability
IntroductiontoAJAX
Nir
Elbaz
Making AJAX requests with raw JavaScript
• Basic steps
• A client event occurs (button click, setTimeout fired…)
• An XMLHttpRequest object is created
• The XMLHttpRequest object is configured
• The XMLHttpRequest object makes an asynchronous request to theWebserver
• Webserver returns the result
• The XMLHttpRequest object calls the callback() function and processes the result
IntroductiontoAJAX
Nir
Elbaz
MakingAJAXrequestswithrawJavaScript
readyState codes:
0: object created but uninitialized
1: loading (opened, not sent)
2: loaded (send but no response)
3: interactive (partial response)
4: complete (full response)
status (HTTP) codes:
1xx: (Provisional response)
2xx: (Successful)
3xx: (Redirected)
4xx: (Request error)
5xx: (Server error)
Samples:
200 - the server successfully returned the page
404 - the requested page doesn't exist
503 - the server is temporarily unavailable
Methods:
open(method, url, async)
send(string)
setRequestHeader(header, value)
IntroductiontoAJAX
Nir
Elbaz
Making AJAX requests with raw JavaScript
• GET or POST?
• GET is faster and simpler than POST
• Use POST in these cases:
• A cached file is not an option (update a file or database on the server)
• Sending a large amount of data to the server (POST has no size limitations)
• Sending user input (which can contain unknown characters)
IntroductiontoAJAX
Nir
Elbaz
Making AJAX requests with raw JavaScript
• Usage samples
GET request (-params, +cache)
xmlhttp.open(“GET”, “myWS.asp”, true);
xmlhttp.send(“”);
GET request (-params, -cache)
xmlhttp.open(“GET”, “myWS.asp?t=” + Math.random(), true);
xmlhttp.send(“”);
GET request (+params, +cache)
xmlhttp.open(“GET”, “myWS.asp?fname=Nir&lname=Elbaz”, true);
xmlhttp.send(“”);
POST request (+params, -cache)
xmlhttp.open(“POST”, “myWS.asp”, true);
xmlhttp.send(“fname=Nir&lname=Elbaz”); // sending params now
IntroductiontoAJAX
Nir
Elbaz
Making AJAX requests with raw JavaScript
• Callback sample
• Can get either free text (e.g. HTML, JS…) or XML document
• Can get response header value with getResponseHeader(‘HEADER’)
IntroductiontoAJAX
Nir
Elbaz
Making AJAX requests with raw JavaScript
• Debugging XHR
• DeveloperTools (Chrome, FireBug….)
• Fiddler
• …
XHR requests logs in Chrome DeveloperTools
IntroductiontoAJAX
Nir
Elbaz
Making AJAX requests with jQuery
• jQuery provides great support forAJAX & simplify usage:
• load(url, data, callback): Load a piece of html into a container DOM
• $.getJSON(url, data, callback): Load a JSON with GET method
• $.getScript(url, callback): Load a JavaScript
• $.get(url, data, callback, type):GenericAJAX GET request
• $.post(url, data, callback, type): Generic AJAX GET request
• $.ajax(options):All purpose AJAX request (higher level abstractions)
Syntacticsugarof$.ajax
GET, POST
GET
GET
POST
GET, POST
IntroductiontoAJAX
Nir
Elbaz
Making AJAX requests with jQuery
• Usage samples
Load (part of a) remote file
$("#result").load(loadUrl);
$("#result").load(loadUrl + " #picture");
// Best practice: Use HTML(‘<img src=“loader.gif” />’)
before calling the load function
Load remote file w/ parameters
$("#result").load(loadUrl, “fname=Nir&lname=Elbaz”); // GET
$("#result").load(loadUrl, {fname:“Nir”, lname:“Elbaz”}); // POST
// Best practice: Use HTML(‘<img src=“loader.gif” />’)
before calling the load function
IntroductiontoAJAX
Nir
Elbaz
Making AJAX requests with jQuery
• Usage samples
Get JSON file (GET only), generate HTML fragment and append to HTML
$.getJSON(“http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?”, {
tags: “Israel”,
tagmode: “any”,
format: “json”
})
.done(function (data) {
$.each(data.items, function(index, item ) {
$(“<img/>”).attr(“src”, item.media.m).appendTo(“#images”);
});
});
JSONP
IntroductiontoAJAX
Nir
Elbaz
Making AJAX requests with jQuery
• Usage samples
Full documentation of the $.ajax method
Send id as data to the server and notify the user once it’s complete or fail
$.ajax({
url: “someWS.ashx”,
type: “POST”,
data: {id : 3},
dataType: "html"
}).done(function (msg) {
$("#log").html(msg);
}).fail(function (jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
IntroductiontoAJAX
Nir
Elbaz
Making AJAX requests with jQuery
• More jQueryAJAX aid methods
• $.ajaxSetup(): Sets the default values for future AJAX requests
• $.param():Creates a serialized representation of an array or object
• ajaxStart(): Specifies a function to run when the first AJAX request begins
• ajaxError(): Specifies a function to run when AJAX request completes with an error
• serialize(): Encodes a set of form elements as a string for submission
• …
IntroductiontoAJAX
Nir
Elbaz
AJAX & ASP.net
• Formerly known as projectATLAS
• Released on 2007 as part of ASP.net v.2
• AJAX is even more crucial onASP.net
web applications (LC,ViewState…)
• Provides few server side controls to
simplify AJAX development but considered
insufficient
IntroductiontoAJAX
Nir
Elbaz
AJAX & ASP.net
• AJAX built-in server side controls
• ScriptManager - Manages script resources for client components
• UpdatePanel * - enables you to refresh selected parts of the page
• UpdateProgress * - Provides status information about partial-page updates in
UpdatePanel controls
• Timer * - Performs postbacks at defined intervals (w or w/o UpdatePanel)
• AJAX ControlsToolkit
• Set of additional server controls which provide highly responsive and interactiveAjax-
enabledWeb applications (link)
* ScriptManager control is required in order to use the UpdatePanel, UpdateProgress, andTimer controls
IntroductiontoAJAX
Nir
Elbaz
AJAX&ASP.net
Veryinefficient-Causesacompletepostback
IntroductiontoAJAX
Nir
Elbaz
AJAX&ASP.net
IntroductiontoAJAX
Nir
Elbaz
AJAX Security
• Server side:
• Same as regular web applications in all aspects
• Client side:
• JS code is visible to a user/hacker, which can use it to search for exploits
IntroductiontoAJAX
Nir
Elbaz
BehindThe Scenes (In a Nutshell)
• A web service is any piece of SW that makes itself available over the internet
• Could be based on various technologies server pages (php, asp|m|hx, sc…)
asmx ashx wcf
IntroductiontoAJAX
Nir
Elbaz
Resources
• http://www.w3schools.com/ajax/
• http://www.tutorialspoint.com/ajax/
• http://en.wikipedia.org/wiki/Ajax_(programming)
• http://net.tutsplus.com/
• http://www.w3schools.com/jquery/jquery_ref_ajax.asp
• http://api.jquery.com/jQuery.ajax/
• http://msdn.microsoft.com/en-us/library/bb398874(v=vs.100).aspx

More Related Content

What's hot (20)

Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Web Development with HTML5, CSS3 & JavaScript
Web Development with HTML5, CSS3 & JavaScriptWeb Development with HTML5, CSS3 & JavaScript
Web Development with HTML5, CSS3 & JavaScript
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
ReactJS
ReactJSReactJS
ReactJS
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Js ppt
Js pptJs ppt
Js ppt
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Front-end development introduction (HTML, CSS). Part 1
Front-end development introduction (HTML, CSS). Part 1Front-end development introduction (HTML, CSS). Part 1
Front-end development introduction (HTML, CSS). Part 1
 

Viewers also liked

An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programminghchen1
 
Ajax Introduction Presentation
Ajax   Introduction   PresentationAjax   Introduction   Presentation
Ajax Introduction Presentationthinkphp
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajaxRaja V
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajaxs_pradeep
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)Raghu nath
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorialoscon2007
 
ASP.NET MVC and ajax
ASP.NET MVC and ajax ASP.NET MVC and ajax
ASP.NET MVC and ajax Brij Mishra
 
основы Ajax презентация
основы Ajax   презентацияосновы Ajax   презентация
основы Ajax презентацияsivorka
 
Fourth Dimension Level 1
Fourth Dimension Level 1Fourth Dimension Level 1
Fourth Dimension Level 1Ehtesham Mirxa
 
MachinePulse Products
MachinePulse ProductsMachinePulse Products
MachinePulse ProductsMachinePulse
 
WebApp / SPA @ AllFacebook Developer Conference
WebApp / SPA @ AllFacebook Developer ConferenceWebApp / SPA @ AllFacebook Developer Conference
WebApp / SPA @ AllFacebook Developer ConferenceAllFacebook.de
 
Intro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETIntro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETAlan Hecht
 

Viewers also liked (20)

An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
 
Ajax Introduction Presentation
Ajax   Introduction   PresentationAjax   Introduction   Presentation
Ajax Introduction Presentation
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Ajax for PHP Developers
Ajax for PHP DevelopersAjax for PHP Developers
Ajax for PHP Developers
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
 
Jsf Ajax
Jsf AjaxJsf Ajax
Jsf Ajax
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorial
 
Technical ppt
Technical pptTechnical ppt
Technical ppt
 
ASP.NET MVC and ajax
ASP.NET MVC and ajax ASP.NET MVC and ajax
ASP.NET MVC and ajax
 
ASP.NET MVC - AJAX
ASP.NET MVC - AJAXASP.NET MVC - AJAX
ASP.NET MVC - AJAX
 
PHP on AJAX
PHP on AJAXPHP on AJAX
PHP on AJAX
 
основы Ajax презентация
основы Ajax   презентацияосновы Ajax   презентация
основы Ajax презентация
 
Fourth Dimension Level 1
Fourth Dimension Level 1Fourth Dimension Level 1
Fourth Dimension Level 1
 
MachinePulse Products
MachinePulse ProductsMachinePulse Products
MachinePulse Products
 
Overview of AJAX
Overview of AJAXOverview of AJAX
Overview of AJAX
 
WebApp / SPA @ AllFacebook Developer Conference
WebApp / SPA @ AllFacebook Developer ConferenceWebApp / SPA @ AllFacebook Developer Conference
WebApp / SPA @ AllFacebook Developer Conference
 
Intro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETIntro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NET
 

Similar to Introduction to ajax

Similar to Introduction to ajax (20)

Introduction to AJAX
Introduction to AJAXIntroduction to AJAX
Introduction to AJAX
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASIT
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Ajaxtechnicalworkshopshortversion 1224845432835700-8
Ajaxtechnicalworkshopshortversion 1224845432835700-8Ajaxtechnicalworkshopshortversion 1224845432835700-8
Ajaxtechnicalworkshopshortversion 1224845432835700-8
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
 
Ajax workshop
Ajax workshopAjax workshop
Ajax workshop
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax Tuturial
Ajax TuturialAjax Tuturial
Ajax Tuturial
 
Ajax
AjaxAjax
Ajax
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
WEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptxWEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptx
 
Ajax
AjaxAjax
Ajax
 
Synapseindia dot net development web applications with ajax
Synapseindia dot net development  web applications with ajaxSynapseindia dot net development  web applications with ajax
Synapseindia dot net development web applications with ajax
 
ITI006En-AJAX
ITI006En-AJAXITI006En-AJAX
ITI006En-AJAX
 
Ajax Under The Hood
Ajax Under The HoodAjax Under The Hood
Ajax Under The Hood
 
Ajax
AjaxAjax
Ajax
 

More from Nir Elbaz

Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignNir Elbaz
 
Hello, AngularJS 1.3
Hello, AngularJS 1.3Hello, AngularJS 1.3
Hello, AngularJS 1.3Nir Elbaz
 
Dalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScriptDalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScriptNir Elbaz
 
this is simple
this is simplethis is simple
this is simpleNir Elbaz
 
IBM Worklight
IBM WorklightIBM Worklight
IBM WorklightNir Elbaz
 
Introduction to html 5
Introduction to html 5Introduction to html 5
Introduction to html 5Nir Elbaz
 

More from Nir Elbaz (6)

Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Hello, AngularJS 1.3
Hello, AngularJS 1.3Hello, AngularJS 1.3
Hello, AngularJS 1.3
 
Dalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScriptDalek.js - Automated cross browser testing with JavaScript
Dalek.js - Automated cross browser testing with JavaScript
 
this is simple
this is simplethis is simple
this is simple
 
IBM Worklight
IBM WorklightIBM Worklight
IBM Worklight
 
Introduction to html 5
Introduction to html 5Introduction to html 5
Introduction to html 5
 

Recently uploaded

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Introduction to ajax

  • 2. IntroductiontoAJAX Nir Elbaz Introduction to AJAX • Index • What is AJAX? • MakingAJAX requests with raw JavaScript • MakingAJAX requests with jQuery • AJAX & ASP.net • AJAX security
  • 3. IntroductiontoAJAX Nir Elbaz What is AJAX • AJAX stands for Asynchronous JavaScript And XML • Allows web pages or parts of them to be updated asynchronously • Based on XML HTTP request object (AKA XHR) • Requires basic understanding of: • (X)HTML – displaying the data • CSS – styling the data • JavaScript – manipulating the DOM • XML / JSON – received / sent data format (also HTML & text) Also refers dynamic content
  • 4. IntroductiontoAJAX Nir Elbaz What is AJAX Browser User Interface Web Server Databases, backend processes HTTP(S)Transport HTTP request HTML/CSS/JS/* response Classic web application model Browser User Interface Web Server Databases, backend processes HTTP(S)Transport HTTP request HTML/CSS/JS/* response AJAX web application model AJAX engine JS call Validresponsecanbeanytextualdata:html,css,js,csv,xml…
  • 5. IntroductiontoAJAX Nir Elbaz What is AJAX Classic web application model AJAX web application model User Front end Back end
  • 6. IntroductiontoAJAX Nir Elbaz What is AJAX • Usage samples • Autocomplete search textboxes (sample) • Cascading dropdown list boxes (sample) • Real-time - Continuous data refresh (long polling, chat systems…) • Immediate forms validation feedback (sample) • Conditional display / dynamic content (sample) • Auto save user information (Google Docs, Facebook) • Ratings, voting & other instant actions (sample)
  • 7. IntroductiontoAJAX Nir Elbaz What is AJAX • Browser support • Mozilla Firefox 1.0 and above • Google Chrome • Apple Safari 1.2 and above • Microsoft Internet Exporer 5 and above (ActiveXObject for lte IE6) • Opera 7.6 and above
  • 8. IntroductiontoAJAX Nir Elbaz What is AJAX • Pros • Better interactivity & responsiveness • Impressive UX • Reduced connections to the web server (partial rendering) • Reduced bandwidth • Its “cool” 
  • 9. IntroductiontoAJAX Nir Elbaz What is AJAX • Cons • The back and refresh button are rendered useless • Bookmarking is useless (HTML 5 History API to the rescue) • Requires JavaScript to be enabled on browsers • SEO & analytics unfriendly • Screen readers unfriendly – affects accessibility • Callbacks can lead to complex code • Network latency may break usability
  • 10. IntroductiontoAJAX Nir Elbaz Making AJAX requests with raw JavaScript • Basic steps • A client event occurs (button click, setTimeout fired…) • An XMLHttpRequest object is created • The XMLHttpRequest object is configured • The XMLHttpRequest object makes an asynchronous request to theWebserver • Webserver returns the result • The XMLHttpRequest object calls the callback() function and processes the result
  • 11. IntroductiontoAJAX Nir Elbaz MakingAJAXrequestswithrawJavaScript readyState codes: 0: object created but uninitialized 1: loading (opened, not sent) 2: loaded (send but no response) 3: interactive (partial response) 4: complete (full response) status (HTTP) codes: 1xx: (Provisional response) 2xx: (Successful) 3xx: (Redirected) 4xx: (Request error) 5xx: (Server error) Samples: 200 - the server successfully returned the page 404 - the requested page doesn't exist 503 - the server is temporarily unavailable Methods: open(method, url, async) send(string) setRequestHeader(header, value)
  • 12. IntroductiontoAJAX Nir Elbaz Making AJAX requests with raw JavaScript • GET or POST? • GET is faster and simpler than POST • Use POST in these cases: • A cached file is not an option (update a file or database on the server) • Sending a large amount of data to the server (POST has no size limitations) • Sending user input (which can contain unknown characters)
  • 13. IntroductiontoAJAX Nir Elbaz Making AJAX requests with raw JavaScript • Usage samples GET request (-params, +cache) xmlhttp.open(“GET”, “myWS.asp”, true); xmlhttp.send(“”); GET request (-params, -cache) xmlhttp.open(“GET”, “myWS.asp?t=” + Math.random(), true); xmlhttp.send(“”); GET request (+params, +cache) xmlhttp.open(“GET”, “myWS.asp?fname=Nir&lname=Elbaz”, true); xmlhttp.send(“”); POST request (+params, -cache) xmlhttp.open(“POST”, “myWS.asp”, true); xmlhttp.send(“fname=Nir&lname=Elbaz”); // sending params now
  • 14. IntroductiontoAJAX Nir Elbaz Making AJAX requests with raw JavaScript • Callback sample • Can get either free text (e.g. HTML, JS…) or XML document • Can get response header value with getResponseHeader(‘HEADER’)
  • 15. IntroductiontoAJAX Nir Elbaz Making AJAX requests with raw JavaScript • Debugging XHR • DeveloperTools (Chrome, FireBug….) • Fiddler • … XHR requests logs in Chrome DeveloperTools
  • 16. IntroductiontoAJAX Nir Elbaz Making AJAX requests with jQuery • jQuery provides great support forAJAX & simplify usage: • load(url, data, callback): Load a piece of html into a container DOM • $.getJSON(url, data, callback): Load a JSON with GET method • $.getScript(url, callback): Load a JavaScript • $.get(url, data, callback, type):GenericAJAX GET request • $.post(url, data, callback, type): Generic AJAX GET request • $.ajax(options):All purpose AJAX request (higher level abstractions) Syntacticsugarof$.ajax GET, POST GET GET POST GET, POST
  • 17. IntroductiontoAJAX Nir Elbaz Making AJAX requests with jQuery • Usage samples Load (part of a) remote file $("#result").load(loadUrl); $("#result").load(loadUrl + " #picture"); // Best practice: Use HTML(‘<img src=“loader.gif” />’) before calling the load function Load remote file w/ parameters $("#result").load(loadUrl, “fname=Nir&lname=Elbaz”); // GET $("#result").load(loadUrl, {fname:“Nir”, lname:“Elbaz”}); // POST // Best practice: Use HTML(‘<img src=“loader.gif” />’) before calling the load function
  • 18. IntroductiontoAJAX Nir Elbaz Making AJAX requests with jQuery • Usage samples Get JSON file (GET only), generate HTML fragment and append to HTML $.getJSON(“http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?”, { tags: “Israel”, tagmode: “any”, format: “json” }) .done(function (data) { $.each(data.items, function(index, item ) { $(“<img/>”).attr(“src”, item.media.m).appendTo(“#images”); }); }); JSONP
  • 19. IntroductiontoAJAX Nir Elbaz Making AJAX requests with jQuery • Usage samples Full documentation of the $.ajax method Send id as data to the server and notify the user once it’s complete or fail $.ajax({ url: “someWS.ashx”, type: “POST”, data: {id : 3}, dataType: "html" }).done(function (msg) { $("#log").html(msg); }).fail(function (jqXHR, textStatus) { alert("Request failed: " + textStatus); });
  • 20. IntroductiontoAJAX Nir Elbaz Making AJAX requests with jQuery • More jQueryAJAX aid methods • $.ajaxSetup(): Sets the default values for future AJAX requests • $.param():Creates a serialized representation of an array or object • ajaxStart(): Specifies a function to run when the first AJAX request begins • ajaxError(): Specifies a function to run when AJAX request completes with an error • serialize(): Encodes a set of form elements as a string for submission • …
  • 21. IntroductiontoAJAX Nir Elbaz AJAX & ASP.net • Formerly known as projectATLAS • Released on 2007 as part of ASP.net v.2 • AJAX is even more crucial onASP.net web applications (LC,ViewState…) • Provides few server side controls to simplify AJAX development but considered insufficient
  • 22. IntroductiontoAJAX Nir Elbaz AJAX & ASP.net • AJAX built-in server side controls • ScriptManager - Manages script resources for client components • UpdatePanel * - enables you to refresh selected parts of the page • UpdateProgress * - Provides status information about partial-page updates in UpdatePanel controls • Timer * - Performs postbacks at defined intervals (w or w/o UpdatePanel) • AJAX ControlsToolkit • Set of additional server controls which provide highly responsive and interactiveAjax- enabledWeb applications (link) * ScriptManager control is required in order to use the UpdatePanel, UpdateProgress, andTimer controls
  • 25. IntroductiontoAJAX Nir Elbaz AJAX Security • Server side: • Same as regular web applications in all aspects • Client side: • JS code is visible to a user/hacker, which can use it to search for exploits
  • 26. IntroductiontoAJAX Nir Elbaz BehindThe Scenes (In a Nutshell) • A web service is any piece of SW that makes itself available over the internet • Could be based on various technologies server pages (php, asp|m|hx, sc…) asmx ashx wcf
  • 27. IntroductiontoAJAX Nir Elbaz Resources • http://www.w3schools.com/ajax/ • http://www.tutorialspoint.com/ajax/ • http://en.wikipedia.org/wiki/Ajax_(programming) • http://net.tutsplus.com/ • http://www.w3schools.com/jquery/jquery_ref_ajax.asp • http://api.jquery.com/jQuery.ajax/ • http://msdn.microsoft.com/en-us/library/bb398874(v=vs.100).aspx