SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Java script ppt
Java script pptJava script ppt
Java script ppt
The Health and Social Care Information Centre
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
engcs2008
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
Samundra khatri
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
namespaceit
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
AngularJS
AngularJS AngularJS
AngularJS
NexThoughts Technologies
 
Intro to React
Intro to ReactIntro to React
Intro to React
Justin Reock
 
Ajax and Jquery
Ajax and JqueryAjax and Jquery
Ajax and Jquery
People Strategists
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
Rob Quick
 
React js
React jsReact js
React js
Oswald Campesato
 
Full stack web development
Full stack web developmentFull stack web development
Full stack web development
Crampete
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
Knoldus Inc.
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
Madhuri Kavade
 
Reactjs
Reactjs Reactjs
Reactjs
Neha Sharma
 
REST API
REST APIREST API
REST API
Tofazzal Ahmed
 
Ajax
AjaxAjax
Ajax
Tech_MX
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
DivyanshGupta922023
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
alaa.moustafa
 
Web api
Web apiWeb api
Web api
Sudhakar Sharma
 

Viewers also liked (20)

Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
Smithss25
 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
hchen1
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
JayaPrakash.m
 
Ajax Introduction Presentation
Ajax   Introduction   PresentationAjax   Introduction   Presentation
Ajax Introduction Presentation
thinkphp
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
Raja V
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
Venkat Pinagadi
 
Ajax for PHP Developers
Ajax for PHP DevelopersAjax for PHP Developers
Ajax for PHP Developers
Michael Girouard
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
John Coggeshall
 
Jsf Ajax
Jsf AjaxJsf Ajax
Jsf Ajax
rajivmordani
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
s_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 Tutorial
oscon2007
 
Technical ppt
Technical pptTechnical ppt
Technical ppt
Priya_Srivastava
 
ASP.NET MVC and ajax
ASP.NET MVC and ajax ASP.NET MVC and ajax
ASP.NET MVC and ajax
Brij Mishra
 
ASP.NET MVC - AJAX
ASP.NET MVC - AJAXASP.NET MVC - AJAX
ASP.NET MVC - AJAX
Danae Aguilar Guzmán
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
PHP on AJAX
PHP on AJAXPHP on AJAX
PHP on AJAX
Ford AntiTrust
 
основы Ajax презентация
основы Ajax   презентацияосновы Ajax   презентация
основы Ajax презентация
sivorka
 
Fourth Dimension Level 1
Fourth Dimension Level 1Fourth Dimension Level 1
Fourth Dimension Level 1
Ehtesham Mirxa
 
MachinePulse Products
MachinePulse ProductsMachinePulse Products
MachinePulse Products
MachinePulse
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
Smithss25
 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
hchen1
 
Ajax Introduction Presentation
Ajax   Introduction   PresentationAjax   Introduction   Presentation
Ajax Introduction Presentation
thinkphp
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
Raja V
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
s_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 Tutorial
oscon2007
 
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 1
Ehtesham Mirxa
 
MachinePulse Products
MachinePulse ProductsMachinePulse Products
MachinePulse Products
MachinePulse
 
Ad

Similar to Introduction to ajax (20)

Introduction to AJAX
Introduction to AJAXIntroduction to AJAX
Introduction to AJAX
Abzetdin Adamov
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASIT
ASIT
 
Web Programming using Asynchronous JavaX
Web Programming using Asynchronous JavaXWeb Programming using Asynchronous JavaX
Web Programming using Asynchronous JavaX
SivanN6
 
Ajax
AjaxAjax
Ajax
Abhishek Kesharwani
 
Ajax
AjaxAjax
Ajax
Manav Prasad
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
Ganesh Chavan
 
Ajaxtechnicalworkshopshortversion 1224845432835700-8
Ajaxtechnicalworkshopshortversion 1224845432835700-8Ajaxtechnicalworkshopshortversion 1224845432835700-8
Ajaxtechnicalworkshopshortversion 1224845432835700-8
anuradha raheja
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
WebVineet
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
Kat Roque
 
Ajax workshop
Ajax workshopAjax workshop
Ajax workshop
WBUTTUTORIALS
 
Ajax
AjaxAjax
Ajax
WBUTTUTORIALS
 
Ajax Tuturial
Ajax TuturialAjax Tuturial
Ajax Tuturial
Anup Singh
 
Ajax
AjaxAjax
Ajax
rahmed_sct
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
itzkuu01
 
WEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptxWEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptx
karthiksmart21
 
Ajax
AjaxAjax
Ajax
Siya Agarwal
 
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
Synapseindiappsdevelopment
 
ITI006En-AJAX
ITI006En-AJAXITI006En-AJAX
ITI006En-AJAX
Huibert Aalbers
 
Ajax Under The Hood
Ajax Under The HoodAjax Under The Hood
Ajax Under The Hood
WO Community
 
Ajax
AjaxAjax
Ajax
husnara mohammad
 
Ad

More from Nir Elbaz (6)

Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Nir Elbaz
 
Hello, AngularJS 1.3
Hello, AngularJS 1.3Hello, AngularJS 1.3
Hello, AngularJS 1.3
Nir 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 JavaScript
Nir Elbaz
 
this is simple
this is simplethis is simple
this is simple
Nir Elbaz
 
IBM Worklight
IBM WorklightIBM Worklight
IBM Worklight
Nir Elbaz
 
Introduction to html 5
Introduction to html 5Introduction to html 5
Introduction to html 5
Nir Elbaz
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Nir Elbaz
 
Hello, AngularJS 1.3
Hello, AngularJS 1.3Hello, AngularJS 1.3
Hello, AngularJS 1.3
Nir 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 JavaScript
Nir Elbaz
 
this is simple
this is simplethis is simple
this is simple
Nir Elbaz
 
IBM Worklight
IBM WorklightIBM Worklight
IBM Worklight
Nir Elbaz
 
Introduction to html 5
Introduction to html 5Introduction to html 5
Introduction to html 5
Nir Elbaz
 

Recently uploaded (20)

HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 

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