SlideShare a Scribd company logo
© RAGINIJAIN CC SA 4.0
Ragini Jain
MSc CA 1st
Year (2015 - 2017)
Ajax
real-life app do's n dont's
© RAGINIJAIN CC SA 4.0
Ajax basics
● At the core
– JavaScript engine
– XmlHttpRequest object
– Asynchronous callback design pattern
● 'X' in ajax can be
– XML
– JSON
– HTML
– plain text
Single threaded event loop
Prototype based inheritance
Functional programming language
enum XMLHttpRequestResponseType {
"",
"arraybuffer",
"blob",
"document",
"json",
"text"
};
© RAGINIJAIN CC SA 4.0
XMLHttpRequest IXMLHttpRequest
nsIXMLHttpRequest
XMLHttpRequest, Level 1
XMLHttpRequest, Level 2
XMLHttpRequest
Microsoft IE 5.0 (1999)
Mozilla Gecko/1.0 (2002)
W3C (April 2006)
W3C (Feb 2008)
W3C, WHATWG (2014)
https://xhr.spec.whatwg.org/
© RAGINIJAIN CC SA 4.0
XMLHttpRequest (XHR)
XHR is an Application level API in JavaScript provided
by the browser
Browser takes care of “low-level”
● Protocol negotiation
● Connection establishment
● Pooling and Termination
● Determines the best HTTP(s) transport (HTTP/1.0, 1.1, 2)
● Handles HTTP caching, redirects and content-type negotiation
● Enforces Security, Authentication and Privacy constraints
●
© RAGINIJAIN CC SA 4.0
● Support for
– Request timeouts
– Binary and text based data transfers
– Application override of media type and encoding of responses
– Monitoring progress events of each request
– Efficient file uploads
– Safe cross-origin requests
XMLHttpRequest level 2 (XHR)
http://caniuse.com/xhr2
© RAGINIJAIN CC SA 4.0
XMLHttpRequest classes
XMLHttpRequest XMLHttpRequestUpload
© RAGINIJAIN CC SA 4.0
XHR event handler
© RAGINIJAIN CC SA 4.0
XMLHttpRequest attribute n methods
Request
● Method
– open( )
– setRequestHeader( )
– send( )
– abort( )
● Attribute
● timeout
● withCredentials
● upload
Response
● Method
– overrideMimeType( )
– getResponseHeader( )
– getAllResponseHeaders( )
● Attribute
– response
– responseURL
– responseType
– responseText
– responseXML
– status
– statusText
© RAGINIJAIN CC SA 4.0
XMLHttpRequest (XHR) benefits
● As a browser-level api handles all the low-level details such as
caching, handling redirects, content negotiation, authentication etc
● Makes application APIs much easier to work with, allowing us to
focus on business logic
● Allows the browser to sandbox
● Allows the browser to enforce a set of security and policy
constraints on the application code
● XHR interface enforces strict HTTP semantics on each request
● XHR API allows the application to add custom HTTP headers
© RAGINIJAIN CC SA 4.0
Asynchronous in Ajax
open(method, url [, async = true [, username = null [, password = null]]])
var request = new XMLHttpRequest();
var method = "GET";
var url = "http://github.com/mexem";
var isAsync = true;
request.open(method, url, isAsync);
if (200 == request.status) {
console.log(request.responseText);
}
© RAGINIJAIN CC SA 4.0
© RAGINIJAIN CC SA 4.0
© RAGINIJAIN CC SA 4.0
© RAGINIJAIN CC SA 4.0
© RAGINIJAIN CC SA 4.0
The changing face of web applications
● SEO (Search Engine Optimization) is critical for ensuring Page
rank
● A page must have a usable / indexable URL
● Application design should not leak through analysis of client side
structure of code
● SSL for transport level security is de-jure
© RAGINIJAIN CC SA 4.0
Ajax DO's
● Use Ajax to save client side content
– Entire form processing can be done using ajax
– When the user hits the save button, ajax can take over
– SEO friendly, since search engine will never click/push a button
on a form and is unaware of the ajax usage
© RAGINIJAIN CC SA 4.0
Ajax DO's
● Use Ajax for user-specific actions
– Set cookies
– Track sessions
– Log actions as long as the content isn't dependent on it
© RAGINIJAIN CC SA 4.0
Ajax DO's
● Use Ajax to save client side content
– Entire form processing can be done using ajax
– When the user hits the save button, ajax can take over
– SEO friendly, since search engine will never click/push a button
on a form and is unaware of the ajax usage
© RAGINIJAIN CC SA 4.0
Ajax DO's
● Use Ajax to do form field validation
– Each form field can be validated using range or regular
expressions or business rules coded in javascript
–
© RAGINIJAIN CC SA 4.0
Ajax DO's
● Use Ajax to display status message
– User interaction should be captured using Ajax and a response
in the form of status message should be shown
– This increases the interactivity of the web application while
maintaining SEO characteristics
© RAGINIJAIN CC SA 4.0
Ajax DO's
● Use Ajax for logical parts of a page but not the whole page
– Real-time updates and interactions cause parts of the page to
update.
– The forward and back buttons of the browser are still working
– The url is a real url which can be bookmarked and shared
–
© RAGINIJAIN CC SA 4.0
Ajax DO's
● External data sources are used to aggregate content for a page.
This leads to slower loading of page
● Use Ajax to load information from external source after loading
the page.
© RAGINIJAIN CC SA 4.0
Ajax DONT's
● Donot use Ajax to display static text content
– Search engines process main page content to calculate page
rank
© RAGINIJAIN CC SA 4.0
Ajax DONT's
● Donot use Ajax for paging a table or list
– Dynamically generated data inside a table or list should be
indexed properly
–
© RAGINIJAIN CC SA 4.0
Ajax DONT's
● Donot use Ajax for navigational purpose
– <A>nchor links should be in HTML and not in Javascript
– Search engines donot follow Javascript links
– Search engines will get stuck on the top link and will exit the
page without indexing it completely
–
© RAGINIJAIN CC SA 4.0
Ajax DONT's
● Donot leak the structure of the database in the key-value pair
updates
● One click is cool, but all the data sent in the Ajax call is a security
nightmare
– Every profile update
– Every key-value pair sent with info about the record which will
be updated
– Multiple key-value pairs sent show a pattern which mirrors the
structure in the database
© RAGINIJAIN CC SA 4.0
Ajax DONT's
● Donot use .innerHTML to adjust the HTML generated response
from the server
● Instead do the adjusting of DOM in JavaScript
● Use JSON to convert server-side variables to JavaScript variables
● This keeps the 'presentation' and 'computation' separate from
each other
● Use arrays of information instead of HTML
●
© RAGINIJAIN CC SA 4.0
Ajax Security : Cross-site scripting (XSS)
http://ruslanbes.com/devblog/2014/10/12/jquery-cross-site-scripting-tutorial-and-de
Same-Origin policy
© RAGINIJAIN CC SA 4.0
References
https://youtu.be/_fUGWFGUrUw
High Performance JavaScript
https://youtu.be/v2ifWcnQs6M
JavaScript, a very successful
Functional programming
language
Nicholas Zakas
© RAGINIJAIN CC SA 4.0
Further Reading
0
© RAGINIJAIN CC SA 4.0
Thank you.
● Questions
● Clarifications
● Suggestions
● Feedback
Ragini Jain
15030142023@sicsr.ac.in

More Related Content

What's hot

Scalable deployment options in WSO2 API Manager
Scalable deployment options in WSO2 API ManagerScalable deployment options in WSO2 API Manager
Scalable deployment options in WSO2 API ManagerWSO2
 
A Tour of Ruby On Rails
A Tour of Ruby On RailsA Tour of Ruby On Rails
A Tour of Ruby On Rails
David Keener
 
Plugins unplugged
Plugins unpluggedPlugins unplugged
Plugins unplugged
Christian Rokitta
 
RESTful API - Best Practices
RESTful API - Best PracticesRESTful API - Best Practices
RESTful API - Best Practices
Tricode (part of Dept)
 
Getting your grips on Excel chaos
Getting your grips on Excel chaosGetting your grips on Excel chaos
Getting your grips on Excel chaos
Niels de Bruijn
 
API Proxy Auto Discovery
API Proxy Auto DiscoveryAPI Proxy Auto Discovery
API Proxy Auto Discovery
Vince Soliza
 
Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0
Eugenio Romano
 
Firebase Basics - Dialog Demo for Group Tech Staff
Firebase Basics - Dialog Demo for Group Tech StaffFirebase Basics - Dialog Demo for Group Tech Staff
Firebase Basics - Dialog Demo for Group Tech Staff
Tharaka Devinda
 

What's hot (8)

Scalable deployment options in WSO2 API Manager
Scalable deployment options in WSO2 API ManagerScalable deployment options in WSO2 API Manager
Scalable deployment options in WSO2 API Manager
 
A Tour of Ruby On Rails
A Tour of Ruby On RailsA Tour of Ruby On Rails
A Tour of Ruby On Rails
 
Plugins unplugged
Plugins unpluggedPlugins unplugged
Plugins unplugged
 
RESTful API - Best Practices
RESTful API - Best PracticesRESTful API - Best Practices
RESTful API - Best Practices
 
Getting your grips on Excel chaos
Getting your grips on Excel chaosGetting your grips on Excel chaos
Getting your grips on Excel chaos
 
API Proxy Auto Discovery
API Proxy Auto DiscoveryAPI Proxy Auto Discovery
API Proxy Auto Discovery
 
Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0
 
Firebase Basics - Dialog Demo for Group Tech Staff
Firebase Basics - Dialog Demo for Group Tech StaffFirebase Basics - Dialog Demo for Group Tech Staff
Firebase Basics - Dialog Demo for Group Tech Staff
 

Similar to Ajax

SynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax DevelopmentSynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax Development
Synapseindiappsdevelopment
 
Hackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platformHackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platform
Ihor Uzhvenko
 
Usability AJAX and other ASP.NET Features
Usability AJAX and other ASP.NET FeaturesUsability AJAX and other ASP.NET Features
Usability AJAX and other ASP.NET Features
Peter Gfader
 
Ajax
AjaxAjax
M Ramya
M RamyaM Ramya
Ajax
AjaxAjax
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
Jignesh Aakoliya
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET Presentation
Rasel Khan
 
AJAX Patterns with ASP.NET
AJAX Patterns with ASP.NETAJAX Patterns with ASP.NET
AJAX Patterns with ASP.NET
goodfriday
 
Asp introduction
Asp introductionAsp introduction
Asp introduction
Sireesh K
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applicationsdominion
 
Ajax ppt
Ajax pptAjax ppt
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
Eamonn Boyle
 
AJAX
AJAXAJAX
AJAXARJUN
 
JOB PORTALProject SummaryTitle JOB-PORT.docx
JOB PORTALProject SummaryTitle    JOB-PORT.docxJOB PORTALProject SummaryTitle    JOB-PORT.docx
JOB PORTALProject SummaryTitle JOB-PORT.docx
christiandean12115
 
AJAX
AJAXAJAX
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJS
Pratik Majumdar
 

Similar to Ajax (20)

Ajax
AjaxAjax
Ajax
 
SynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax DevelopmentSynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax Development
 
Hackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platformHackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platform
 
Usability AJAX and other ASP.NET Features
Usability AJAX and other ASP.NET FeaturesUsability AJAX and other ASP.NET Features
Usability AJAX and other ASP.NET Features
 
Ajax
AjaxAjax
Ajax
 
M Ramya
M RamyaM Ramya
M Ramya
 
Ajax
AjaxAjax
Ajax
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
 
Walther Aspnet4
Walther Aspnet4Walther Aspnet4
Walther Aspnet4
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET Presentation
 
AJAX Patterns with ASP.NET
AJAX Patterns with ASP.NETAJAX Patterns with ASP.NET
AJAX Patterns with ASP.NET
 
Asp introduction
Asp introductionAsp introduction
Asp introduction
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
 
Walther Ajax4
Walther Ajax4Walther Ajax4
Walther Ajax4
 
AJAX
AJAXAJAX
AJAX
 
JOB PORTALProject SummaryTitle JOB-PORT.docx
JOB PORTALProject SummaryTitle    JOB-PORT.docxJOB PORTALProject SummaryTitle    JOB-PORT.docx
JOB PORTALProject SummaryTitle JOB-PORT.docx
 
AJAX
AJAXAJAX
AJAX
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJS
 

Recently uploaded

UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
Sayali Powar
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
Nguyen Thanh Tu Collection
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Sourabh Kumar
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
ricssacare
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 

Recently uploaded (20)

UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 

Ajax

  • 1. © RAGINIJAIN CC SA 4.0 Ragini Jain MSc CA 1st Year (2015 - 2017) Ajax real-life app do's n dont's
  • 2. © RAGINIJAIN CC SA 4.0 Ajax basics ● At the core – JavaScript engine – XmlHttpRequest object – Asynchronous callback design pattern ● 'X' in ajax can be – XML – JSON – HTML – plain text Single threaded event loop Prototype based inheritance Functional programming language enum XMLHttpRequestResponseType { "", "arraybuffer", "blob", "document", "json", "text" };
  • 3. © RAGINIJAIN CC SA 4.0 XMLHttpRequest IXMLHttpRequest nsIXMLHttpRequest XMLHttpRequest, Level 1 XMLHttpRequest, Level 2 XMLHttpRequest Microsoft IE 5.0 (1999) Mozilla Gecko/1.0 (2002) W3C (April 2006) W3C (Feb 2008) W3C, WHATWG (2014) https://xhr.spec.whatwg.org/
  • 4. © RAGINIJAIN CC SA 4.0 XMLHttpRequest (XHR) XHR is an Application level API in JavaScript provided by the browser Browser takes care of “low-level” ● Protocol negotiation ● Connection establishment ● Pooling and Termination ● Determines the best HTTP(s) transport (HTTP/1.0, 1.1, 2) ● Handles HTTP caching, redirects and content-type negotiation ● Enforces Security, Authentication and Privacy constraints ●
  • 5. © RAGINIJAIN CC SA 4.0 ● Support for – Request timeouts – Binary and text based data transfers – Application override of media type and encoding of responses – Monitoring progress events of each request – Efficient file uploads – Safe cross-origin requests XMLHttpRequest level 2 (XHR) http://caniuse.com/xhr2
  • 6. © RAGINIJAIN CC SA 4.0 XMLHttpRequest classes XMLHttpRequest XMLHttpRequestUpload
  • 7. © RAGINIJAIN CC SA 4.0 XHR event handler
  • 8. © RAGINIJAIN CC SA 4.0 XMLHttpRequest attribute n methods Request ● Method – open( ) – setRequestHeader( ) – send( ) – abort( ) ● Attribute ● timeout ● withCredentials ● upload Response ● Method – overrideMimeType( ) – getResponseHeader( ) – getAllResponseHeaders( ) ● Attribute – response – responseURL – responseType – responseText – responseXML – status – statusText
  • 9. © RAGINIJAIN CC SA 4.0 XMLHttpRequest (XHR) benefits ● As a browser-level api handles all the low-level details such as caching, handling redirects, content negotiation, authentication etc ● Makes application APIs much easier to work with, allowing us to focus on business logic ● Allows the browser to sandbox ● Allows the browser to enforce a set of security and policy constraints on the application code ● XHR interface enforces strict HTTP semantics on each request ● XHR API allows the application to add custom HTTP headers
  • 10. © RAGINIJAIN CC SA 4.0 Asynchronous in Ajax open(method, url [, async = true [, username = null [, password = null]]]) var request = new XMLHttpRequest(); var method = "GET"; var url = "http://github.com/mexem"; var isAsync = true; request.open(method, url, isAsync); if (200 == request.status) { console.log(request.responseText); }
  • 15. © RAGINIJAIN CC SA 4.0 The changing face of web applications ● SEO (Search Engine Optimization) is critical for ensuring Page rank ● A page must have a usable / indexable URL ● Application design should not leak through analysis of client side structure of code ● SSL for transport level security is de-jure
  • 16. © RAGINIJAIN CC SA 4.0 Ajax DO's ● Use Ajax to save client side content – Entire form processing can be done using ajax – When the user hits the save button, ajax can take over – SEO friendly, since search engine will never click/push a button on a form and is unaware of the ajax usage
  • 17. © RAGINIJAIN CC SA 4.0 Ajax DO's ● Use Ajax for user-specific actions – Set cookies – Track sessions – Log actions as long as the content isn't dependent on it
  • 18. © RAGINIJAIN CC SA 4.0 Ajax DO's ● Use Ajax to save client side content – Entire form processing can be done using ajax – When the user hits the save button, ajax can take over – SEO friendly, since search engine will never click/push a button on a form and is unaware of the ajax usage
  • 19. © RAGINIJAIN CC SA 4.0 Ajax DO's ● Use Ajax to do form field validation – Each form field can be validated using range or regular expressions or business rules coded in javascript –
  • 20. © RAGINIJAIN CC SA 4.0 Ajax DO's ● Use Ajax to display status message – User interaction should be captured using Ajax and a response in the form of status message should be shown – This increases the interactivity of the web application while maintaining SEO characteristics
  • 21. © RAGINIJAIN CC SA 4.0 Ajax DO's ● Use Ajax for logical parts of a page but not the whole page – Real-time updates and interactions cause parts of the page to update. – The forward and back buttons of the browser are still working – The url is a real url which can be bookmarked and shared –
  • 22. © RAGINIJAIN CC SA 4.0 Ajax DO's ● External data sources are used to aggregate content for a page. This leads to slower loading of page ● Use Ajax to load information from external source after loading the page.
  • 23. © RAGINIJAIN CC SA 4.0 Ajax DONT's ● Donot use Ajax to display static text content – Search engines process main page content to calculate page rank
  • 24. © RAGINIJAIN CC SA 4.0 Ajax DONT's ● Donot use Ajax for paging a table or list – Dynamically generated data inside a table or list should be indexed properly –
  • 25. © RAGINIJAIN CC SA 4.0 Ajax DONT's ● Donot use Ajax for navigational purpose – <A>nchor links should be in HTML and not in Javascript – Search engines donot follow Javascript links – Search engines will get stuck on the top link and will exit the page without indexing it completely –
  • 26. © RAGINIJAIN CC SA 4.0 Ajax DONT's ● Donot leak the structure of the database in the key-value pair updates ● One click is cool, but all the data sent in the Ajax call is a security nightmare – Every profile update – Every key-value pair sent with info about the record which will be updated – Multiple key-value pairs sent show a pattern which mirrors the structure in the database
  • 27. © RAGINIJAIN CC SA 4.0 Ajax DONT's ● Donot use .innerHTML to adjust the HTML generated response from the server ● Instead do the adjusting of DOM in JavaScript ● Use JSON to convert server-side variables to JavaScript variables ● This keeps the 'presentation' and 'computation' separate from each other ● Use arrays of information instead of HTML ●
  • 28. © RAGINIJAIN CC SA 4.0 Ajax Security : Cross-site scripting (XSS) http://ruslanbes.com/devblog/2014/10/12/jquery-cross-site-scripting-tutorial-and-de Same-Origin policy
  • 29. © RAGINIJAIN CC SA 4.0 References https://youtu.be/_fUGWFGUrUw High Performance JavaScript https://youtu.be/v2ifWcnQs6M JavaScript, a very successful Functional programming language Nicholas Zakas
  • 30. © RAGINIJAIN CC SA 4.0 Further Reading 0
  • 31. © RAGINIJAIN CC SA 4.0 Thank you. ● Questions ● Clarifications ● Suggestions ● Feedback Ragini Jain 15030142023@sicsr.ac.in