SlideShare una empresa de Scribd logo
1 de 51
Descargar para leer sin conexión
AJAX Transport Layer

       Siarhei Barysiuk
s.barysiuk@sam-solutions.net
Our roadmap
AJAX... not just for toilet cleaning anymore


                • AJAX = Asynchronous JavaScript and XML

                • Ajax is set of technologies that allow web
                applications to provide rich interaction
                without whole page refreshing.
Ajax: Classic Web Application
                      1) Browser makes request to server
                      2) Server sends HTML/CSS response
Ajax: Ajax Web Application
                      1) Browser makes request to server
                      asynchronously
                      2) Server sends XML/JSON response
                      3) AJAX Engine processes response
XMLHttpRequest
XMLHttpRequest: Fetching data flow

                       1) User generates an event (e.g. button click)
                       2) System creates an XMLHttpRequest and
                       configures with request parameters.
                       3) The XMLHttpRequest object makes an
                       asynchronous request to the web server.
                       4) Web server returns XML(other) object
                       with data.
                       5) The XMLHttpRequest object receives the
                       XML data and calls a callback to process it.
XMLHttpRequest: XHR Interface
                        event listener                                     XHR State
   // event handler
 attribute EventListener onreadystatechange;

 // state
 const unsigned short UNSENT = 0;
 const unsigned short OPENED = 1;
 const unsigned short HEADERS_RECEIVED = 2;
                                                                               open
 const unsigned short LOADING = 3;
 const unsigned short DONE = 4;
                                                                               send
 readonly attribute unsigned short readyState;

                                                                               abort
 // request
 void open(in DOMString method, in DOMString url);
 void open(in DOMString method, in DOMString url, in boolean async);
 void open(in DOMString method, in DOMString url, in boolean async, in DOMString user);
 void open(in DOMString method, in DOMString url, in boolean async, in DOMString user, in DOMString password);
 void setRequestHeader(in DOMString header, in DOMString value);
 void send();
 void send(in DOMString data);
 void send(in Document data);
 void abort();

                                                                            Response
 // response

                                                                           (Text/XML)
 DOMString getAllResponseHeaders();
 DOMString getResponseHeader(in DOMString header);
 readonly attribute DOMString responseText;
 readonly attribute Document responseXML;
 readonly attribute unsigned short status;
 readonly attribute DOMString statusText;
XMLHttpRequest: How to get XHR
function getXHR() {
	 var request = null;
	
	 if (typeof XMLHttpRequest != 'undefined') {
	 	 request = new XMLHttpRequest();
	}
	 else {
	 	 try {
	 	 	 request = new ActiveXObject(quot;Msxml2.XMLHTTPquot;);
		}
	 	 catch (e) {
	 	 	 try {
	 	 	 	 request = new ActiveXObject(quot;Microsoft.XMLHTTPquot;);
			}
	 	 	 catch (e) {}
	 	 }	
	}
		
	 return request;
}
XMLHttpRequest: Using XHR
var READY_STATE_COMPLETE=4;

var request = getXHR();   1
	
                                                      2
request.onreadystatechange = function() {
	 if (request.readyState == READY_STATE_COMPLETE) {
	 	 //200 OK
	 	 if (request.status == 200) { 5.1
	 	 	 //process data
		}
	 	 //Some error
                         5.2
	 	 else {
	 	 	 //process error
		}
	}
};
request.open(method,url,true); 3
request.send(null); 4
XMLHttpRequest: An example
A classic example is linked drop-downs.



                               Regions    Cities
XMLHttpRequest: Supported methods
• GET
Requests a representation of the specified resource. By far the most common method used on the Web
today.
• POST
Submits data to be processed (e.g. from an HTML form) to the identified resource. The data is included in
the body of the request. This may result in the creation of a new resource or the updates of existing
resources or both.
• HEAD
Asks for the response identical to the one that would correspond to a GET request, but without the
response body. This is useful for retrieving meta-information written in response headers, without having
to transport the entire content.
• PUT
Uploads a representation of the specified resource.
• DELETE
Deletes the specified resource.
• OPTIONS
This method allows the client to determine the options and/or requirements associated with a resource.
XMLHttpRequest: GET method
var READY_STATE_COMPLETE=4;
                              1
var request = getXHR();
	
                                                      2
request.onreadystatechange = function() {
	 if (request.readyState == READY_STATE_COMPLETE) {
	 	 //200 OK
	 	 if (request.status == 200) {    5.1
	 	 	 //process data
		}
	 	 //Some error
	 	 else {                 5.2
	 	 	 //process error
                                                              is asynchronous?
		}
	}
};
request.open(quot;GETquot;, quot;/path?param1=value1&param2=value2quot;,true); 3

request.send(null);   4
XMLHttpRequest: POST method
var READY_STATE_COMPLETE=4;
                              1
var request = getXHR();
	
                                                      2
request.onreadystatechange = function() {
	 if (request.readyState == READY_STATE_COMPLETE) {
	 	 //200 OK
	 	 if (request.status == 200) {    5.1
	 	 	 //process data
		}
	 	 //Some error
	 	 else {                 5.2
	 	 	 //process error
                                  is asynchronous?
		}
	}
};
request.open(quot;POSTquot;, quot;/pathquot;,true);     3

request.send(quot;param1=value1&param2=value2quot;);   4
XMLHttpRequest: Features

• object available in IE/Mozilla/Opera/Safari
• synchronous and asynchronous requests
• POST and GET support
XMLHttpRequest: Pros and Cons

+ not limited to XML
+ asynchronous calls
+ can receive HTTP status codes/headers
+ supported GET and POST
- back button problems
- same-origin policy
XMLHttpRequest: Same-origin policy
The philosophy of the same origin policy is simple: the browser should
not trust content loaded from arbitrary websites.
The term quot;originquot; is defined using the domain name, protocol and port.

                       URL                     Outcome                     Reason

 http://www.example.com/dir2/other.html        Success            Same protocol and host

 http://www.example.com/dir/inner/other.html   Success            Same protocol and host

 http://www.example.com:81/dir2/other.html      Failure   Same protocol and host but different port

 https://www.example.com/dir2/other.html        Failure              Different protocol

 http://en.example.com/dir2/other.html          Failure                 Different host

 http://example.com/dir2/other.html             Failure                 Different host
Questions?
iframe transport
iframe transport: Fetching data flow

                         1) User generates an event (e.g. button click)
                         2) System creates a hidden IFrame and
                         configures with request parameters.
                         3) The IFrame element makes an request to
                         the web server.
                         4) Web server returns XML(other) object
                         with data.
                         5) The IFrame object receives the XML data
                         and fires a load event.
iframe transport: How to use

var iframe = document.createElement(quot;iframequot;); 1
iframe.width=quot;0quot;;
iframe.height=quot;0quot;;
...
iframe.onload = bind(this.callback, this); 2
...                                                          GET
iframe.src = this.url + quot;?quot; + this.getRequestString();   3
...
document.body.appendChild(this.iframe);	 4




       In order to use POST you need to
   {                                           }
       create <form> and fill it dynamically.
iframe transport: How to use

var iframe = document.createElement(quot;iframequot;); 1
iframe.width=quot;0quot;;
iframe.height=quot;0quot;;
...
iframe.onload = bind(this.callback, this); 2
...                                                          GET
iframe.src = this.url + quot;?quot; + this.getRequestString();   3
...
document.body.appendChild(this.iframe);	 4

<iframe>
	 <!-- ... -->
	 <script type=quot;text/javascriptquot;>
	 	 window.parent.someFunction(/*data here*/);
	 </script>
	 <!-- ... -->
</iframe>
iframe transport: An example
 Linked drop-downs example.



                               Regions   Cities
iframe transport: Pros and Cons
+ wide browser compatibility

- browser history
- iframe not supported by XHTML strict
- cross-domain policy
iframe transport: Cross-domain policy
...
iframe.src = this.url + quot;?quot; + this.getRequestString();
...
                                                          different than current
<iframe>
                                                         http://host:port/path
	 <!-- ... -->
	 <script type=quot;text/javascriptquot;>
	 	 window.parent.handleIframeResponse(/*data here*/);
	 </script>
	 <!-- ... -->
</iframe>
Questions?
img cookie transport
img cookie transport: What is cookie?
Technically, cookies are arbitrary pieces of data chosen by the Web server and
sent to the browser.
img cookie transport: Cookies limitations
Relevant count of maximum stored cookies per domain for the major browsers
are:
          Firefox 2

          Firefox 3

        Opera 9.30

               IE 6

               IE 7

                          Safari has no limit.
             Safari

                      0                     12.5   25.0   37.5   50.0


Cookies must be smaller than 4 kilobytes. Internet Explorer imposes a 4KB
total for all cookies stored in a given domain.
img cookie transport: Fetching data flow




 1) Create <img> with request URL and append it to body. Browser makes a
 request to the server.
 2) Server sets cookies and sends response to the client.
 3) Client checks cookies after some time interval.
img cookie transport: An example
...

var img = document.createElement(quot;imgquot;); 1
img.width = quot;0quot;;
img.heigth = quot;0quot;;
	
img.src = this.url + quot;?quot; + this.getRequestString(this.data); 2

...
document.body.appendChild(this.img); 3
...

setTimeout(bind(this.callback,this),this.interval); 4
img cookie transport: Pros and Cons
+ lightweight
+ really really extra wide compatibility

- limited data due to GET and cookie limits
Questions?
script transport
script transport: Fetching data flow




     1) Create <script> element with given src attribute. Browser makes
     request to the server.
     2) Server returns JSON data wrapped in function call.
     3) Client runs function in own context.
script transport: JSON? What is it?

    JSON (JavaScript Object Notation) is a lightweight data-interchange format.

• It is easy for humans to read and write.
• It is easy for machines to parse and generate.
• It is based on a subset of the JavaScript Programming Language.
• It is a text format that is completely language independent.
script transport: JSON? What is it?
{
	 {quot;menuquot;: {
  	 	 quot;idquot;: quot;filequot;,
   	
  	 	 quot;valuequot;: quot;Filequot;,
   	
 	 	 	 quot;popupquot;: {
     		 	 	      quot;menuitemquot;: [
       		 	 	 	                {quot;valuequot;: quot;Newquot;, quot;onclickquot;: quot;CreateNewDoc()quot;},
       		 	 	 	 	              {quot;valuequot;: quot;Openquot;, quot;onclickquot;: quot;OpenDoc()quot;},
       		 	 	 	 	 	             {quot;valuequot;: quot;Closequot;, quot;onclickquot;: quot;CloseDoc()quot;}
     		 	 	 	 	 	            ]
  		
   	            }
			         }
   }		 	
}
script transport: An example
del.icio.us mashup
script transport: Pros and Cons
+ exempt from Same Origin restriction
+ less overhead (headers, cookies)
- JSON only
- GET method only
script transport: JSONP extension
Pass a name of callback function as jsonp parameter.


http://somehost:port/path?jsonp=funcName&param1=value1


            jsonp + quot;(quot; + jsonResult + quot;);quot;
Questions?
comet
comet: Intro
Named after kitchen cleaning.
comet: What is it?

Fundamentally, [Comet applications] all use long-lived HTTP
connections to reduce the latency with which messages
are passed to the server.

In essence, they do not poll the server occasionally. Instead
the server has an open line of communication with which
it can push data to the client.
comet: Who’s using it?
comet: Classic Ajax Application
comet: Comet Application
comet: An example
Highly interactive applications like chats, real-time games, etc.
comet: Pros and Cons
+ low latency
+ event-based server push
- client 2 connection limit
- pragmatically requires custom server component
   Cometd
   LightStreamer
   ...
Questions?

Más contenido relacionado

La actualidad más candente

Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsSolution4Future
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server InternalsPraveen Gollakota
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rackdanwrong
 
Tornado web
Tornado webTornado web
Tornado webkurtiss
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node jsfakedarren
 
Nginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/sNginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/smoret1979
 
Python, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBPython, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBemptysquare
 
Real time server
Real time serverReal time server
Real time serverthepian
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecturepostrational
 
An Introduction to Solr
An Introduction to SolrAn Introduction to Solr
An Introduction to Solrtomhill
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsAdrien Guéret
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksAddy Osmani
 

La actualidad más candente (20)

Tornadoweb
TornadowebTornadoweb
Tornadoweb
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
 
Web::Scraper
Web::ScraperWeb::Scraper
Web::Scraper
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server Internals
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rack
 
Tornado web
Tornado webTornado web
Tornado web
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Nginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/sNginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/s
 
Python, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBPython, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDB
 
Real time server
Real time serverReal time server
Real time server
 
Tornado in Depth
Tornado in DepthTornado in Depth
Tornado in Depth
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecture
 
An Introduction to Solr
An Introduction to SolrAn Introduction to Solr
An Introduction to Solr
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Rest api with Python
Rest api with PythonRest api with Python
Rest api with Python
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & Tricks
 
JavaScript JQUERY AJAX
JavaScript JQUERY AJAXJavaScript JQUERY AJAX
JavaScript JQUERY AJAX
 

Destacado

Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesDoris Chen
 
Server Side Events
Server Side EventsServer Side Events
Server Side Eventsthepilif
 
A Re-Introduction to Third-Party Scripting
A Re-Introduction to Third-Party ScriptingA Re-Introduction to Third-Party Scripting
A Re-Introduction to Third-Party Scriptingbenvinegar
 
Behind the scenes of Real-Time Notifications
Behind the scenes of Real-Time NotificationsBehind the scenes of Real-Time Notifications
Behind the scenes of Real-Time NotificationsGuillermo Mansilla
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsBG Java EE Course
 

Destacado (7)

Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
 
Server Side Events
Server Side EventsServer Side Events
Server Side Events
 
A Re-Introduction to Third-Party Scripting
A Re-Introduction to Third-Party ScriptingA Re-Introduction to Third-Party Scripting
A Re-Introduction to Third-Party Scripting
 
Behind the scenes of Real-Time Notifications
Behind the scenes of Real-Time NotificationsBehind the scenes of Real-Time Notifications
Behind the scenes of Real-Time Notifications
 
Ajax
AjaxAjax
Ajax
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
 
jQuery Ajax
jQuery AjaxjQuery Ajax
jQuery Ajax
 

Similar a AJAX Transport Layer Comparison

Similar a AJAX Transport Layer Comparison (20)

AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Ajax and xml
Ajax and xmlAjax and xml
Ajax and xml
 
AJAX
AJAXAJAX
AJAX
 
AJAX
AJAXAJAX
AJAX
 
AJAX
AJAXAJAX
AJAX
 
Ajax
AjaxAjax
Ajax
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
Introduction to Ajax programming
Introduction to Ajax programmingIntroduction to Ajax programming
Introduction to Ajax programming
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax Technology
Ajax TechnologyAjax Technology
Ajax Technology
 
RIA and Ajax
RIA and AjaxRIA and Ajax
RIA and Ajax
 
Xml http request
Xml http requestXml http request
Xml http request
 
Core Java tutorial at Unit Nexus
Core Java tutorial at Unit NexusCore Java tutorial at Unit Nexus
Core Java tutorial at Unit Nexus
 
AJAX
AJAXAJAX
AJAX
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 

Último

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Último (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

AJAX Transport Layer Comparison

  • 1.
  • 2. AJAX Transport Layer Siarhei Barysiuk s.barysiuk@sam-solutions.net
  • 4. AJAX... not just for toilet cleaning anymore • AJAX = Asynchronous JavaScript and XML • Ajax is set of technologies that allow web applications to provide rich interaction without whole page refreshing.
  • 5. Ajax: Classic Web Application 1) Browser makes request to server 2) Server sends HTML/CSS response
  • 6. Ajax: Ajax Web Application 1) Browser makes request to server asynchronously 2) Server sends XML/JSON response 3) AJAX Engine processes response
  • 8. XMLHttpRequest: Fetching data flow 1) User generates an event (e.g. button click) 2) System creates an XMLHttpRequest and configures with request parameters. 3) The XMLHttpRequest object makes an asynchronous request to the web server. 4) Web server returns XML(other) object with data. 5) The XMLHttpRequest object receives the XML data and calls a callback to process it.
  • 9. XMLHttpRequest: XHR Interface event listener XHR State // event handler attribute EventListener onreadystatechange; // state const unsigned short UNSENT = 0; const unsigned short OPENED = 1; const unsigned short HEADERS_RECEIVED = 2; open const unsigned short LOADING = 3; const unsigned short DONE = 4; send readonly attribute unsigned short readyState; abort // request void open(in DOMString method, in DOMString url); void open(in DOMString method, in DOMString url, in boolean async); void open(in DOMString method, in DOMString url, in boolean async, in DOMString user); void open(in DOMString method, in DOMString url, in boolean async, in DOMString user, in DOMString password); void setRequestHeader(in DOMString header, in DOMString value); void send(); void send(in DOMString data); void send(in Document data); void abort(); Response // response (Text/XML) DOMString getAllResponseHeaders(); DOMString getResponseHeader(in DOMString header); readonly attribute DOMString responseText; readonly attribute Document responseXML; readonly attribute unsigned short status; readonly attribute DOMString statusText;
  • 10. XMLHttpRequest: How to get XHR function getXHR() { var request = null; if (typeof XMLHttpRequest != 'undefined') { request = new XMLHttpRequest(); } else { try { request = new ActiveXObject(quot;Msxml2.XMLHTTPquot;); } catch (e) { try { request = new ActiveXObject(quot;Microsoft.XMLHTTPquot;); } catch (e) {} } } return request; }
  • 11. XMLHttpRequest: Using XHR var READY_STATE_COMPLETE=4; var request = getXHR(); 1 2 request.onreadystatechange = function() { if (request.readyState == READY_STATE_COMPLETE) { //200 OK if (request.status == 200) { 5.1 //process data } //Some error 5.2 else { //process error } } }; request.open(method,url,true); 3 request.send(null); 4
  • 12. XMLHttpRequest: An example A classic example is linked drop-downs. Regions Cities
  • 13. XMLHttpRequest: Supported methods • GET Requests a representation of the specified resource. By far the most common method used on the Web today. • POST Submits data to be processed (e.g. from an HTML form) to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both. • HEAD Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content. • PUT Uploads a representation of the specified resource. • DELETE Deletes the specified resource. • OPTIONS This method allows the client to determine the options and/or requirements associated with a resource.
  • 14. XMLHttpRequest: GET method var READY_STATE_COMPLETE=4; 1 var request = getXHR(); 2 request.onreadystatechange = function() { if (request.readyState == READY_STATE_COMPLETE) { //200 OK if (request.status == 200) { 5.1 //process data } //Some error else { 5.2 //process error is asynchronous? } } }; request.open(quot;GETquot;, quot;/path?param1=value1&param2=value2quot;,true); 3 request.send(null); 4
  • 15. XMLHttpRequest: POST method var READY_STATE_COMPLETE=4; 1 var request = getXHR(); 2 request.onreadystatechange = function() { if (request.readyState == READY_STATE_COMPLETE) { //200 OK if (request.status == 200) { 5.1 //process data } //Some error else { 5.2 //process error is asynchronous? } } }; request.open(quot;POSTquot;, quot;/pathquot;,true); 3 request.send(quot;param1=value1&param2=value2quot;); 4
  • 16. XMLHttpRequest: Features • object available in IE/Mozilla/Opera/Safari • synchronous and asynchronous requests • POST and GET support
  • 17. XMLHttpRequest: Pros and Cons + not limited to XML + asynchronous calls + can receive HTTP status codes/headers + supported GET and POST - back button problems - same-origin policy
  • 18. XMLHttpRequest: Same-origin policy The philosophy of the same origin policy is simple: the browser should not trust content loaded from arbitrary websites. The term quot;originquot; is defined using the domain name, protocol and port. URL Outcome Reason http://www.example.com/dir2/other.html Success Same protocol and host http://www.example.com/dir/inner/other.html Success Same protocol and host http://www.example.com:81/dir2/other.html Failure Same protocol and host but different port https://www.example.com/dir2/other.html Failure Different protocol http://en.example.com/dir2/other.html Failure Different host http://example.com/dir2/other.html Failure Different host
  • 21. iframe transport: Fetching data flow 1) User generates an event (e.g. button click) 2) System creates a hidden IFrame and configures with request parameters. 3) The IFrame element makes an request to the web server. 4) Web server returns XML(other) object with data. 5) The IFrame object receives the XML data and fires a load event.
  • 22. iframe transport: How to use var iframe = document.createElement(quot;iframequot;); 1 iframe.width=quot;0quot;; iframe.height=quot;0quot;; ... iframe.onload = bind(this.callback, this); 2 ... GET iframe.src = this.url + quot;?quot; + this.getRequestString(); 3 ... document.body.appendChild(this.iframe); 4 In order to use POST you need to { } create <form> and fill it dynamically.
  • 23. iframe transport: How to use var iframe = document.createElement(quot;iframequot;); 1 iframe.width=quot;0quot;; iframe.height=quot;0quot;; ... iframe.onload = bind(this.callback, this); 2 ... GET iframe.src = this.url + quot;?quot; + this.getRequestString(); 3 ... document.body.appendChild(this.iframe); 4 <iframe> <!-- ... --> <script type=quot;text/javascriptquot;> window.parent.someFunction(/*data here*/); </script> <!-- ... --> </iframe>
  • 24. iframe transport: An example Linked drop-downs example. Regions Cities
  • 25. iframe transport: Pros and Cons + wide browser compatibility - browser history - iframe not supported by XHTML strict - cross-domain policy
  • 26. iframe transport: Cross-domain policy ... iframe.src = this.url + quot;?quot; + this.getRequestString(); ... different than current <iframe> http://host:port/path <!-- ... --> <script type=quot;text/javascriptquot;> window.parent.handleIframeResponse(/*data here*/); </script> <!-- ... --> </iframe>
  • 29. img cookie transport: What is cookie? Technically, cookies are arbitrary pieces of data chosen by the Web server and sent to the browser.
  • 30. img cookie transport: Cookies limitations Relevant count of maximum stored cookies per domain for the major browsers are: Firefox 2 Firefox 3 Opera 9.30 IE 6 IE 7 Safari has no limit. Safari 0 12.5 25.0 37.5 50.0 Cookies must be smaller than 4 kilobytes. Internet Explorer imposes a 4KB total for all cookies stored in a given domain.
  • 31. img cookie transport: Fetching data flow 1) Create <img> with request URL and append it to body. Browser makes a request to the server. 2) Server sets cookies and sends response to the client. 3) Client checks cookies after some time interval.
  • 32. img cookie transport: An example ... var img = document.createElement(quot;imgquot;); 1 img.width = quot;0quot;; img.heigth = quot;0quot;; img.src = this.url + quot;?quot; + this.getRequestString(this.data); 2 ... document.body.appendChild(this.img); 3 ... setTimeout(bind(this.callback,this),this.interval); 4
  • 33. img cookie transport: Pros and Cons + lightweight + really really extra wide compatibility - limited data due to GET and cookie limits
  • 36. script transport: Fetching data flow 1) Create <script> element with given src attribute. Browser makes request to the server. 2) Server returns JSON data wrapped in function call. 3) Client runs function in own context.
  • 37. script transport: JSON? What is it? JSON (JavaScript Object Notation) is a lightweight data-interchange format. • It is easy for humans to read and write. • It is easy for machines to parse and generate. • It is based on a subset of the JavaScript Programming Language. • It is a text format that is completely language independent.
  • 38. script transport: JSON? What is it? { {quot;menuquot;: { quot;idquot;: quot;filequot;, quot;valuequot;: quot;Filequot;, quot;popupquot;: { quot;menuitemquot;: [ {quot;valuequot;: quot;Newquot;, quot;onclickquot;: quot;CreateNewDoc()quot;}, {quot;valuequot;: quot;Openquot;, quot;onclickquot;: quot;OpenDoc()quot;}, {quot;valuequot;: quot;Closequot;, quot;onclickquot;: quot;CloseDoc()quot;} ] } } } }
  • 39. script transport: An example del.icio.us mashup
  • 40. script transport: Pros and Cons + exempt from Same Origin restriction + less overhead (headers, cookies) - JSON only - GET method only
  • 41. script transport: JSONP extension Pass a name of callback function as jsonp parameter. http://somehost:port/path?jsonp=funcName&param1=value1 jsonp + quot;(quot; + jsonResult + quot;);quot;
  • 43. comet
  • 44. comet: Intro Named after kitchen cleaning.
  • 45. comet: What is it? Fundamentally, [Comet applications] all use long-lived HTTP connections to reduce the latency with which messages are passed to the server. In essence, they do not poll the server occasionally. Instead the server has an open line of communication with which it can push data to the client.
  • 47. comet: Classic Ajax Application
  • 49. comet: An example Highly interactive applications like chats, real-time games, etc.
  • 50. comet: Pros and Cons + low latency + event-based server push - client 2 connection limit - pragmatically requires custom server component Cometd LightStreamer ...