SlideShare a Scribd company logo
1 of 32
Download to read offline
Web development



                                                          Client-side programming

                                                         Rich Internet Applications
                                                                 and AJAX




/home/corno/Mirror/elite/slide/Computers/Programming/Languages/JavaScript/AJAX/ajax_v1.odp
Rich Internet Application
Rich Internet applications (RIA) are web
applications that have the features and
functionality of traditional desktop
applications.
RIAs typically
  transfer the processing necessary for the user
  interface to the web client
  keep the bulk of the data (i.e., maintaining the
  state of the program, the data etc) back on the
  application server.
Main goals of RIAs
Most sophisticated RIAs exhibit a look and
feel approaching a desktop environment.
  Richer. User-interface behaviors not obtainable
  using only the HTML widgets available to
  standard browser-based Web applications: drag
  and drop, using a slider to change data,
  calculations performed by the client and which
  do not need to be sent back to the server, ...
  More responsive. The interface behaviors are
  typically much more responsive than those of a
  standard Web browser that must always interact
  with a remote server.
Performance of RIAs
Client/Server balance. The demand for
client and server computing resources is
better balanced. This frees server resources,
allowing the same server hardware to handle
more client sessions concurrently.
Performance of RIAs
Asynchronous communication. The client
engine can interact with the server without
waiting for the user to perform an interface
action such as clicking on a button or link.
This allows the user to view and interact with
the page asynchronously from the client
engine's communication with the server.
  Example: prefetching (an application anticipates
  a future need for certain data, and downloads it
  to the client before the user requests it)
Performance or RIAs
Network efficiency. Network traffic may be
significantly reduced because an application-
specific client engine can be more intelligent
than a Web browser when deciding what
data needs to be exchanged with servers.
  Less data is being transferred for each
  interaction, and overall network load is reduced.
  However, use of asynchronous prefetching
  techniques can neutralize or even reverse this
  potential benefit.
AJAX definition
Asynchronous JavaScript And XML.
AJAX is a type of programming made
popular in 2005 by Google (with Google
Suggest).
AJAX is not a new programming language,
but a new way to use existing standards.
With AJAX you can create better, faster, and
more user-friendly web applications.
AJAX is based on JavaScript and HTTP
requests.
Key enabling technology
With AJAX, your JavaScript can
communicate directly with the server, using
the JavaScript XMLHttpRequest object.
By using the XMLHttpRequest object, a web
developer can update a page with data from
the server -- after the page has loaded!
The XMLHttpRequest object is supported in
Internet Explorer 5.0+, Safari 1.2, Mozilla
1.0 / Firefox, Opera 8+, and Netscape 7.
http://www.w3.org/TR/XMLHttpRequest/
XMLHttpRequest – the name
The name of the object is wrong, but
maintained for historical reasons:
  May receive any text-based content, not just
  XML
  May use also HTTPS, not just HTTP protocol
  May handle both Requests and Responses, of
  all HTTP methods
Standard definition
interface XMLHttpRequest {
  // event handler
           attribute EventListener onreadystatechange;
  // state
  const unsigned short UNSENT = 0;
  const unsigned short OPENED = 1;
  const unsigned short HEADERS_RECEIVED = 2;
  const unsigned short LOADING = 3;
  const unsigned short DONE = 4;
  readonly attribute unsigned short readyState;
Standard definition
  // 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();
Standard definition
     // response
     DOMString getAllResponseHeaders();
     DOMString getResponseHeader(in DOMString header);
     readonly attribute DOMString responseText;
     readonly attribute Document responseXML;
     readonly attribute unsigned short status;
     readonly attribute DOMString statusText;
};
Request states
UNSENT = 0
 The request is not initialized
OPENED = 1
 The request has been set up
HEADERS_RECEIVED = 2
 The request has been sent
LOADING = 3
 The request is in process
DONE = 4
 The request is complete
State transition diagram
                       .setRequestHeader()
new
                              OPENED                  OPENED
      UNSENT     .open()
                              not sent                  sent
                                         .send()
                                                            .send()

          Connection closed                   All headers
                                              received
 DONE       DONE
                             LOADING
  error    not error
                                                    HEADERS
                                    (partial) body _RECEIVED
             Connection closed      received
XMLHttpRequest properties
onreadystatechange
  stores the function that will process the
  response from a server
  xmlHttp.onreadystatechange =
  function() { ... }
readyState
  holds the status of the server’s response. Each
  time readyState changes, the
  onreadystatechange function will be executed.
responseText
  the data sent back from the server can be
  retrieved with the responseText property
Methods
open(method, url, async, user, password)
  method = “GET”, “POST”
  url = complete URL to request
  async = true/false (optional, default=true)
  user, password (optional)
  Interrupts any on-going send()
setRequestHeader(header, value)
  Adds a new header to the HTTP Request
  Content-Type is one common header to send
    Examples: text/xml, application/xml
Methods
send(data)
  Initiates the request
  data = HTTP request body (optional)
    May be a Document or DOMString
  The URL was already given in open()
  send() terminates immediately if async==true,
  but transfer continues in the background
    Generates readystatechange events
  send() transfers data synchronously if
  async==false
Methods
getAllResponseHeaders()
  Return all response headers as a single string,
  with headers separated by CR+LF
  Invalid if UNSENT or OPENED
getResponseHeader(header)
  Returns the value of a single header
  Invalid if UNSENT or OPENED
Receiving the response body
responseText of type DOMString
  If LOADING (partial body) or DONE
  Allow access to a “raw string” of the response
  body
responseXML of type Document
  Only if DONE
  For text/xml (or application/xml or *+xml) content
  types, otherwise null
  Allows access to the DOM of the XML document
Example
Create a standard HTML form with two text
fields: username and time.
The username field will be filled in by the
user and the time field will be filled in using
AJAX.
No submit button is needed.
Example

<html>
<body> <form name="myForm">
Name: <input type="text" name="username" />
Time: <input type="text" name="time" />
</form> </body>
</html>
Creating an XMLHttpRequest
 object
<script type="text/javascript">
function ajaxFunction()
{
  var xmlHttp;
  xmlHttp=new XMLHttpRequest();

  ...
}
</script>
Supporting all browsers
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e) {
  // Internet Explorer
  try { // Internet Explorer 6.0+
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e) {
    try { // Internet Explorer 5.5+
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e) {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
}
</script>
Calling the server
xmlHttp.open("GET","time.jsp",true);
xmlHttp.send(null);
Processing the response

xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
  {
  // Get the data from the server's response
  document.myForm.time.value=xmlHttp.responseText;
  }
}
Attaching to an event

<form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" /
>
Time: <input type="text" name="time" />
</form>
Complete example
<html>
<body>
<script type="text/javascript">
function ajaxFunction()
{
  var xmlHttp=new XMLHttpRequest();

 xmlHttp.onreadystatechange=function()
   {
   if(xmlHttp.readyState==4)
     {
     document.myForm.time.value=xmlHttp.responseText;
     }
   }

  xmlHttp.open("GET","time.asp",true);
  xmlHttp.send(null);
  }
</script>
<form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form> </body>
</html>
AJAX architecture
AJAX
behavior
Exercise 1
Create an auto-complete feature for entering
the name in a FORM
For every typed letter, an associated text
must be updated, reflecting the list of all
possible names with those initial(s)
Once submitted, the name adds up to the list
Clicking on the suggestion auto-fills the box

Name Jo               Suggestions: Joe, Joseph, John

      SUBMIT
Exercise 2
Create a FORM for entering the name of a
city, based on two drop-down menus
(<select> tags).
  The first <select> contains the list of all
  provinces (AO, BO, CN, MI, TO, ...)
  The second <select> contains the list of all cities
  in the province
Every time the user changes the province,
then the list of cities MUST be updated
The form may be submitted only if
information is complete
References
http://en.wikipedia.org/wiki/Rich_Internet_Ap
plications
http://en.wikipedia.org/wiki/AJAX
http://www.w3schools.com/ajax/
http://www.w3.org/TR/XMLHttpRequest/

More Related Content

What's hot

Web II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksWeb II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksRandy Connolly
 
Interoperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSITInteroperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSITCarol McDonald
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSCarol McDonald
 
Using Java to implement SOAP Web Services: JAX-WS
Using Java to implement SOAP Web Services: JAX-WS�Using Java to implement SOAP Web Services: JAX-WS�
Using Java to implement SOAP Web Services: JAX-WSKatrien Verbert
 
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RSFahad Golra
 
ASP.NET 02 - How ASP.NET Works
ASP.NET 02 - How ASP.NET WorksASP.NET 02 - How ASP.NET Works
ASP.NET 02 - How ASP.NET WorksRandy Connolly
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State ManagementRandy Connolly
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface pptTaha Malampatti
 
Java Servlets
Java ServletsJava Servlets
Java ServletsEmprovise
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Masoud Kalali
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...WebStackAcademy
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-frameworkSakthi Bro
 

What's hot (20)

Web II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksWeb II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET Works
 
Interoperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSITInteroperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSIT
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
 
Using Java to implement SOAP Web Services: JAX-WS
Using Java to implement SOAP Web Services: JAX-WS�Using Java to implement SOAP Web Services: JAX-WS�
Using Java to implement SOAP Web Services: JAX-WS
 
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RS
 
ASP.NET 02 - How ASP.NET Works
ASP.NET 02 - How ASP.NET WorksASP.NET 02 - How ASP.NET Works
ASP.NET 02 - How ASP.NET Works
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
 
Ajax
AjaxAjax
Ajax
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
 
M Ramya
M RamyaM Ramya
M Ramya
 
JAX-WS Basics
JAX-WS BasicsJAX-WS Basics
JAX-WS Basics
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
JSON and XML
JSON and XMLJSON and XML
JSON and XML
 
SERVIET
SERVIETSERVIET
SERVIET
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Servlets intro
Servlets introServlets intro
Servlets intro
 
Library Project
Library ProjectLibrary Project
Library Project
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-framework
 

Viewers also liked

Search and Optimization Strategies
Search and Optimization StrategiesSearch and Optimization Strategies
Search and Optimization StrategiesFulvio Corno
 
Ausili definizioni e normative
Ausili definizioni e normativeAusili definizioni e normative
Ausili definizioni e normativeFulvio Corno
 
Accessibilità dei siti web
Accessibilità dei siti webAccessibilità dei siti web
Accessibilità dei siti webFulvio Corno
 
Presentazione Servizio Poli@Home
Presentazione Servizio Poli@HomePresentazione Servizio Poli@Home
Presentazione Servizio Poli@HomeFulvio Corno
 
Logic and Reasoning in the Semantic Web (part II –OWL)
Logic and Reasoning in the Semantic Web (part II –OWL)Logic and Reasoning in the Semantic Web (part II –OWL)
Logic and Reasoning in the Semantic Web (part II –OWL)Fulvio Corno
 
Logic and Reasoning in the Semantic Web
Logic and Reasoning in the Semantic WebLogic and Reasoning in the Semantic Web
Logic and Reasoning in the Semantic WebFulvio Corno
 
Introduction to Javascript programming
Introduction to Javascript programmingIntroduction to Javascript programming
Introduction to Javascript programmingFulvio Corno
 
Linked Data for Ambient Intelligence
Linked Data for Ambient IntelligenceLinked Data for Ambient Intelligence
Linked Data for Ambient IntelligenceFulvio Corno
 
Logic and Reasoning in the Semantic Web (part I –RDF/RDFS)
Logic and Reasoning in the Semantic Web (part I –RDF/RDFS)Logic and Reasoning in the Semantic Web (part I –RDF/RDFS)
Logic and Reasoning in the Semantic Web (part I –RDF/RDFS)Fulvio Corno
 
Computational complexity
Computational complexityComputational complexity
Computational complexityFulvio Corno
 
Lucidi relativi al DVD di Programmazione in C
Lucidi relativi al DVD di Programmazione in CLucidi relativi al DVD di Programmazione in C
Lucidi relativi al DVD di Programmazione in CFulvio Corno
 
Web services in PHP using the NuSOAP library
Web services in PHP using the NuSOAP libraryWeb services in PHP using the NuSOAP library
Web services in PHP using the NuSOAP libraryFulvio Corno
 
Introduction to SKOS - Simple Knowledge Organization System
Introduction to SKOS - Simple Knowledge Organization SystemIntroduction to SKOS - Simple Knowledge Organization System
Introduction to SKOS - Simple Knowledge Organization SystemFulvio Corno
 
Semantic Web, Metadata, Knowledge Representation, Ontologies
Semantic Web, Metadata, Knowledge Representation, OntologiesSemantic Web, Metadata, Knowledge Representation, Ontologies
Semantic Web, Metadata, Knowledge Representation, OntologiesFulvio Corno
 

Viewers also liked (17)

Search and Optimization Strategies
Search and Optimization StrategiesSearch and Optimization Strategies
Search and Optimization Strategies
 
Ausili definizioni e normative
Ausili definizioni e normativeAusili definizioni e normative
Ausili definizioni e normative
 
Accessibilità dei siti web
Accessibilità dei siti webAccessibilità dei siti web
Accessibilità dei siti web
 
Presentazione Servizio Poli@Home
Presentazione Servizio Poli@HomePresentazione Servizio Poli@Home
Presentazione Servizio Poli@Home
 
Web Accessibility
Web AccessibilityWeb Accessibility
Web Accessibility
 
Logic and Reasoning in the Semantic Web (part II –OWL)
Logic and Reasoning in the Semantic Web (part II –OWL)Logic and Reasoning in the Semantic Web (part II –OWL)
Logic and Reasoning in the Semantic Web (part II –OWL)
 
Logic and Reasoning in the Semantic Web
Logic and Reasoning in the Semantic WebLogic and Reasoning in the Semantic Web
Logic and Reasoning in the Semantic Web
 
Introduction to Javascript programming
Introduction to Javascript programmingIntroduction to Javascript programming
Introduction to Javascript programming
 
Linked Data for Ambient Intelligence
Linked Data for Ambient IntelligenceLinked Data for Ambient Intelligence
Linked Data for Ambient Intelligence
 
Logic and Reasoning in the Semantic Web (part I –RDF/RDFS)
Logic and Reasoning in the Semantic Web (part I –RDF/RDFS)Logic and Reasoning in the Semantic Web (part I –RDF/RDFS)
Logic and Reasoning in the Semantic Web (part I –RDF/RDFS)
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
 
Computational complexity
Computational complexityComputational complexity
Computational complexity
 
Web Transactions
Web TransactionsWeb Transactions
Web Transactions
 
Lucidi relativi al DVD di Programmazione in C
Lucidi relativi al DVD di Programmazione in CLucidi relativi al DVD di Programmazione in C
Lucidi relativi al DVD di Programmazione in C
 
Web services in PHP using the NuSOAP library
Web services in PHP using the NuSOAP libraryWeb services in PHP using the NuSOAP library
Web services in PHP using the NuSOAP library
 
Introduction to SKOS - Simple Knowledge Organization System
Introduction to SKOS - Simple Knowledge Organization SystemIntroduction to SKOS - Simple Knowledge Organization System
Introduction to SKOS - Simple Knowledge Organization System
 
Semantic Web, Metadata, Knowledge Representation, Ontologies
Semantic Web, Metadata, Knowledge Representation, OntologiesSemantic Web, Metadata, Knowledge Representation, Ontologies
Semantic Web, Metadata, Knowledge Representation, Ontologies
 

Similar to Introduction to Ajax programming

Similar to Introduction to Ajax programming (20)

Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax
AjaxAjax
Ajax
 
Ajax and xml
Ajax and xmlAjax and xml
Ajax and xml
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
Core Java tutorial at Unit Nexus
Core Java tutorial at Unit NexusCore Java tutorial at Unit Nexus
Core Java tutorial at Unit Nexus
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
AJAX Transport Layer
AJAX Transport LayerAJAX Transport Layer
AJAX Transport Layer
 
AJAX
AJAXAJAX
AJAX
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
Mashup
MashupMashup
Mashup
 
Ajax
AjaxAjax
Ajax
 

Recently uploaded

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

Introduction to Ajax programming

  • 1. Web development Client-side programming Rich Internet Applications and AJAX /home/corno/Mirror/elite/slide/Computers/Programming/Languages/JavaScript/AJAX/ajax_v1.odp
  • 2. Rich Internet Application Rich Internet applications (RIA) are web applications that have the features and functionality of traditional desktop applications. RIAs typically transfer the processing necessary for the user interface to the web client keep the bulk of the data (i.e., maintaining the state of the program, the data etc) back on the application server.
  • 3. Main goals of RIAs Most sophisticated RIAs exhibit a look and feel approaching a desktop environment. Richer. User-interface behaviors not obtainable using only the HTML widgets available to standard browser-based Web applications: drag and drop, using a slider to change data, calculations performed by the client and which do not need to be sent back to the server, ... More responsive. The interface behaviors are typically much more responsive than those of a standard Web browser that must always interact with a remote server.
  • 4. Performance of RIAs Client/Server balance. The demand for client and server computing resources is better balanced. This frees server resources, allowing the same server hardware to handle more client sessions concurrently.
  • 5. Performance of RIAs Asynchronous communication. The client engine can interact with the server without waiting for the user to perform an interface action such as clicking on a button or link. This allows the user to view and interact with the page asynchronously from the client engine's communication with the server. Example: prefetching (an application anticipates a future need for certain data, and downloads it to the client before the user requests it)
  • 6. Performance or RIAs Network efficiency. Network traffic may be significantly reduced because an application- specific client engine can be more intelligent than a Web browser when deciding what data needs to be exchanged with servers. Less data is being transferred for each interaction, and overall network load is reduced. However, use of asynchronous prefetching techniques can neutralize or even reverse this potential benefit.
  • 7. AJAX definition Asynchronous JavaScript And XML. AJAX is a type of programming made popular in 2005 by Google (with Google Suggest). AJAX is not a new programming language, but a new way to use existing standards. With AJAX you can create better, faster, and more user-friendly web applications. AJAX is based on JavaScript and HTTP requests.
  • 8. Key enabling technology With AJAX, your JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. By using the XMLHttpRequest object, a web developer can update a page with data from the server -- after the page has loaded! The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, Opera 8+, and Netscape 7. http://www.w3.org/TR/XMLHttpRequest/
  • 9. XMLHttpRequest – the name The name of the object is wrong, but maintained for historical reasons: May receive any text-based content, not just XML May use also HTTPS, not just HTTP protocol May handle both Requests and Responses, of all HTTP methods
  • 10. Standard definition interface XMLHttpRequest { // event handler attribute EventListener onreadystatechange; // state const unsigned short UNSENT = 0; const unsigned short OPENED = 1; const unsigned short HEADERS_RECEIVED = 2; const unsigned short LOADING = 3; const unsigned short DONE = 4; readonly attribute unsigned short readyState;
  • 11. Standard definition // 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();
  • 12. Standard definition // response DOMString getAllResponseHeaders(); DOMString getResponseHeader(in DOMString header); readonly attribute DOMString responseText; readonly attribute Document responseXML; readonly attribute unsigned short status; readonly attribute DOMString statusText; };
  • 13. Request states UNSENT = 0 The request is not initialized OPENED = 1 The request has been set up HEADERS_RECEIVED = 2 The request has been sent LOADING = 3 The request is in process DONE = 4 The request is complete
  • 14. State transition diagram .setRequestHeader() new OPENED OPENED UNSENT .open() not sent sent .send() .send() Connection closed All headers received DONE DONE LOADING error not error HEADERS (partial) body _RECEIVED Connection closed received
  • 15. XMLHttpRequest properties onreadystatechange stores the function that will process the response from a server xmlHttp.onreadystatechange = function() { ... } readyState holds the status of the server’s response. Each time readyState changes, the onreadystatechange function will be executed. responseText the data sent back from the server can be retrieved with the responseText property
  • 16. Methods open(method, url, async, user, password) method = “GET”, “POST” url = complete URL to request async = true/false (optional, default=true) user, password (optional) Interrupts any on-going send() setRequestHeader(header, value) Adds a new header to the HTTP Request Content-Type is one common header to send Examples: text/xml, application/xml
  • 17. Methods send(data) Initiates the request data = HTTP request body (optional) May be a Document or DOMString The URL was already given in open() send() terminates immediately if async==true, but transfer continues in the background Generates readystatechange events send() transfers data synchronously if async==false
  • 18. Methods getAllResponseHeaders() Return all response headers as a single string, with headers separated by CR+LF Invalid if UNSENT or OPENED getResponseHeader(header) Returns the value of a single header Invalid if UNSENT or OPENED
  • 19. Receiving the response body responseText of type DOMString If LOADING (partial body) or DONE Allow access to a “raw string” of the response body responseXML of type Document Only if DONE For text/xml (or application/xml or *+xml) content types, otherwise null Allows access to the DOM of the XML document
  • 20. Example Create a standard HTML form with two text fields: username and time. The username field will be filled in by the user and the time field will be filled in using AJAX. No submit button is needed.
  • 21. Example <html> <body> <form name="myForm"> Name: <input type="text" name="username" /> Time: <input type="text" name="time" /> </form> </body> </html>
  • 22. Creating an XMLHttpRequest object <script type="text/javascript"> function ajaxFunction() { var xmlHttp; xmlHttp=new XMLHttpRequest(); ... } </script>
  • 23. Supporting all browsers <script type="text/javascript"> function ajaxFunction() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { // Internet Explorer 6.0+ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { // Internet Explorer 5.5+ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } } </script>
  • 25. Processing the response xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { // Get the data from the server's response document.myForm.time.value=xmlHttp.responseText; } }
  • 26. Attaching to an event <form name="myForm"> Name: <input type="text" onkeyup="ajaxFunction();" name="username" / > Time: <input type="text" name="time" /> </form>
  • 27. Complete example <html> <body> <script type="text/javascript"> function ajaxFunction() { var xmlHttp=new XMLHttpRequest(); xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.myForm.time.value=xmlHttp.responseText; } } xmlHttp.open("GET","time.asp",true); xmlHttp.send(null); } </script> <form name="myForm"> Name: <input type="text" onkeyup="ajaxFunction();" name="username" /> Time: <input type="text" name="time" /> </form> </body> </html>
  • 30. Exercise 1 Create an auto-complete feature for entering the name in a FORM For every typed letter, an associated text must be updated, reflecting the list of all possible names with those initial(s) Once submitted, the name adds up to the list Clicking on the suggestion auto-fills the box Name Jo Suggestions: Joe, Joseph, John SUBMIT
  • 31. Exercise 2 Create a FORM for entering the name of a city, based on two drop-down menus (<select> tags). The first <select> contains the list of all provinces (AO, BO, CN, MI, TO, ...) The second <select> contains the list of all cities in the province Every time the user changes the province, then the list of cities MUST be updated The form may be submitted only if information is complete