SlideShare a Scribd company logo
Web Technology Introduction
Collin Smith (Dec. 16, 2006)
AJAX
AJAX Outline
• What is AJAX?
• Benefits
• Real world examples
• How it works
• Code review
• Samples
What is AJAX?
• Asynchronous JavaScript and XML(AJAX)
• Web development technique for creating web
applications
• Makes web pages more responsive by exchanging
small amounts of data
• Allows the web page to change its content without
refreshing the whole page
• A web browser technology independent of web
server software
Benefits
• Improves the user experience
– Analyzing information typed into browser in real
time
– Provide a richer experience
– Increases responsiveness of web pages
• Improve bandwidth utilization
– Only data which is required is retrieved from the
server
Real World Examples
• Google Maps (http://maps.google.com/)
(slidable maps)
• My Yahoo! (http://my.yahoo.com/) (shuffling
windows)
How it works
• AJAX runs in your browser
• Works with asynchronous data transfers(HTTP
requests) between the browser and the web server
• Http requests are sent by javascript calls without
having to submit a form
• XML is commonly used as the format for receiving
server data but plain text may be used as well
1 – XMLHttpRequest object
• A page element must make a javascript call
• The javascript function must create an XMLHttpRequest
object which is used to contact the server
• Javascript must determine whether the client is IE or Firefox
• http = new ActiveXObject("Microsoft.XMLHTTP"); (IE)
• http = new XMLHttpRequest(); (Mozilla)
2 - Sending the request
• Once the XMLHttpRequest object has been created it must
be set up to call the server
• http.open("GET", serverurl, true);
• http.onreadystatechange = jsMethodToHandleResponse;
• http.send(null);
• The code above utilizes the XMLHttpRequest object to
contact the server and retrieve server data
• When the response returns the javascript method
jsMethodToHandleResponse can update the page
3 - Handling the Response
• Implementation of the javascript method which will be used
to handle the response (Event Handler)
• function jsMethodToHandleResponse(str)
• {
• //simply take the response returned an update an html
element with the returned value from the server
• document.getElementById("result").innerHTML = str;
• }
• Now the page has communicated with the server without
having to refresh the entire page
readyState property
• The XMLHttpRequest readyState property defines the
current state of the XMLHttpRequest object
• Possible values for the readyState
• Usually we are usually only concerned with state 4
State Description
0 The request is not initialized
1 The request has been setup
2 The request has been submitted
3 The request is in process
4 The request is completed
Sample Code
• Simply unzip the sample code into a JSP Location
and go to index.jsp
• There are various examples that show some AJAX
functionality
• It is all JSP to make it easy to setup and easy to see
the code.
• The JSPs are generic enough to be easily to
converted to other technologies (.NET or PHP)
References
• http://en.wikipedia.org/wiki/Ajax_
%28programming%29
• http://www.w3schools.com/ajax/default.asp

More Related Content

What's hot

Overview of AJAX
Overview of AJAXOverview of AJAX
Overview of AJAX
Roshith S Pai
 
Ajax
AjaxAjax
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
jrdoane
 
Ajax
AjaxAjax
Serverless GraphQL. AppSync 101
Serverless GraphQL. AppSync 101Serverless GraphQL. AppSync 101
Serverless GraphQL. AppSync 101
Marcin Sodkiewicz
 
Join semantics in kafka streams
Join semantics in kafka streamsJoin semantics in kafka streams
Join semantics in kafka streams
Knoldus Inc.
 
Logging in The World of DevOps
Logging in The World of DevOps Logging in The World of DevOps
Logging in The World of DevOps
DevOps Indonesia
 
Introduction to cloud computing
Introduction to cloud computingIntroduction to cloud computing
Introduction to cloud computingVijay Kalangi
 
Cloud Abstraction Libraries: Implementation and Comparison
Cloud Abstraction Libraries: Implementation and ComparisonCloud Abstraction Libraries: Implementation and Comparison
Cloud Abstraction Libraries: Implementation and Comparison
Udit Agarwal
 
RxJS streams handling for Padawan
RxJS streams handling for PadawanRxJS streams handling for Padawan
RxJS streams handling for Padawan
Seven Peaks Speaks
 
Part Two: Building Web Apps with the MERN Stack
Part Two: Building Web Apps with the MERN StackPart Two: Building Web Apps with the MERN Stack
Part Two: Building Web Apps with the MERN Stack
MongoDB
 
Asp.Net MVC
Asp.Net MVCAsp.Net MVC
Asp.Net MVC
Sudheesh Valathil
 
Taste of RxJS
Taste of RxJSTaste of RxJS
Taste of RxJS
Md. Ziaul Haq
 
Ruby onrails overview
Ruby onrails overviewRuby onrails overview
Ruby onrails overview
Piyush Chand
 

What's hot (20)

Overview of AJAX
Overview of AJAXOverview of AJAX
Overview of AJAX
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
nodejs
nodejsnodejs
nodejs
 
Ajax
Ajax Ajax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Serverless GraphQL. AppSync 101
Serverless GraphQL. AppSync 101Serverless GraphQL. AppSync 101
Serverless GraphQL. AppSync 101
 
AJAX
AJAXAJAX
AJAX
 
Join semantics in kafka streams
Join semantics in kafka streamsJoin semantics in kafka streams
Join semantics in kafka streams
 
Logging in The World of DevOps
Logging in The World of DevOps Logging in The World of DevOps
Logging in The World of DevOps
 
Introduction to cloud computing
Introduction to cloud computingIntroduction to cloud computing
Introduction to cloud computing
 
Cloud Abstraction Libraries: Implementation and Comparison
Cloud Abstraction Libraries: Implementation and ComparisonCloud Abstraction Libraries: Implementation and Comparison
Cloud Abstraction Libraries: Implementation and Comparison
 
RxJS streams handling for Padawan
RxJS streams handling for PadawanRxJS streams handling for Padawan
RxJS streams handling for Padawan
 
Part Two: Building Web Apps with the MERN Stack
Part Two: Building Web Apps with the MERN StackPart Two: Building Web Apps with the MERN Stack
Part Two: Building Web Apps with the MERN Stack
 
Asp.Net MVC
Asp.Net MVCAsp.Net MVC
Asp.Net MVC
 
Taste of RxJS
Taste of RxJSTaste of RxJS
Taste of RxJS
 
Ruby onrails overview
Ruby onrails overviewRuby onrails overview
Ruby onrails overview
 

Similar to Ajax

AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
Ganesh Chavan
 
Ajax ppt
Ajax pptAjax ppt
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
WebVineet
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
javaScript and jQuery
javaScript and jQueryjavaScript and jQuery
javaScript and jQuery
Mehrab Hossain
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASIT
ASIT
 
AJAX Introduction [Autosaved].pptx
AJAX Introduction [Autosaved].pptxAJAX Introduction [Autosaved].pptx
AJAX Introduction [Autosaved].pptx
Jobin86
 
ITI006En-AJAX
ITI006En-AJAXITI006En-AJAX
ITI006En-AJAX
Huibert Aalbers
 
WEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptxWEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptx
karthiksmart21
 
Ajax
AjaxAjax

Similar to Ajax (20)

Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Ajax
Ajax Ajax
Ajax
 
Ajax
AjaxAjax
Ajax
 
javaScript and jQuery
javaScript and jQueryjavaScript and jQuery
javaScript and jQuery
 
Ajax
AjaxAjax
Ajax
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASIT
 
AJAX Introduction [Autosaved].pptx
AJAX Introduction [Autosaved].pptxAJAX Introduction [Autosaved].pptx
AJAX Introduction [Autosaved].pptx
 
ITI006En-AJAX
ITI006En-AJAXITI006En-AJAX
ITI006En-AJAX
 
WEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptxWEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptx
 
Ajax Tuturial
Ajax TuturialAjax Tuturial
Ajax Tuturial
 
Ajax
AjaxAjax
Ajax
 
Introduction to AJAX
Introduction to AJAXIntroduction to AJAX
Introduction to AJAX
 
Ajax
AjaxAjax
Ajax
 
AJAX
AJAXAJAX
AJAX
 

More from WBUTTUTORIALS

Software testing-and-analysis
Software testing-and-analysisSoftware testing-and-analysis
Software testing-and-analysis
WBUTTUTORIALS
 
Query optimisation
Query optimisationQuery optimisation
Query optimisation
WBUTTUTORIALS
 
Fuzzy logic-introduction
Fuzzy logic-introductionFuzzy logic-introduction
Fuzzy logic-introduction
WBUTTUTORIALS
 
Failure mode-and-effects-analysis
Failure mode-and-effects-analysisFailure mode-and-effects-analysis
Failure mode-and-effects-analysis
WBUTTUTORIALS
 
Direct memory access
Direct memory accessDirect memory access
Direct memory access
WBUTTUTORIALS
 
Cost volume-profit-relationships
Cost volume-profit-relationshipsCost volume-profit-relationships
Cost volume-profit-relationships
WBUTTUTORIALS
 
Control unit-implementation
Control unit-implementationControl unit-implementation
Control unit-implementation
WBUTTUTORIALS
 
Relational model
Relational modelRelational model
Relational model
WBUTTUTORIALS
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimization
WBUTTUTORIALS
 
Data communications-concepts
Data communications-conceptsData communications-concepts
Data communications-concepts
WBUTTUTORIALS
 
Ajax workshop
Ajax workshopAjax workshop
Ajax workshop
WBUTTUTORIALS
 
Ajax toolkit-framework
Ajax toolkit-frameworkAjax toolkit-framework
Ajax toolkit-framework
WBUTTUTORIALS
 

More from WBUTTUTORIALS (12)

Software testing-and-analysis
Software testing-and-analysisSoftware testing-and-analysis
Software testing-and-analysis
 
Query optimisation
Query optimisationQuery optimisation
Query optimisation
 
Fuzzy logic-introduction
Fuzzy logic-introductionFuzzy logic-introduction
Fuzzy logic-introduction
 
Failure mode-and-effects-analysis
Failure mode-and-effects-analysisFailure mode-and-effects-analysis
Failure mode-and-effects-analysis
 
Direct memory access
Direct memory accessDirect memory access
Direct memory access
 
Cost volume-profit-relationships
Cost volume-profit-relationshipsCost volume-profit-relationships
Cost volume-profit-relationships
 
Control unit-implementation
Control unit-implementationControl unit-implementation
Control unit-implementation
 
Relational model
Relational modelRelational model
Relational model
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimization
 
Data communications-concepts
Data communications-conceptsData communications-concepts
Data communications-concepts
 
Ajax workshop
Ajax workshopAjax workshop
Ajax workshop
 
Ajax toolkit-framework
Ajax toolkit-frameworkAjax toolkit-framework
Ajax toolkit-framework
 

Recently uploaded

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
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
 
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
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
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
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 

Recently uploaded (20)

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
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
 
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
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.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 ...
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 

Ajax

  • 1. Web Technology Introduction Collin Smith (Dec. 16, 2006) AJAX
  • 2. AJAX Outline • What is AJAX? • Benefits • Real world examples • How it works • Code review • Samples
  • 3. What is AJAX? • Asynchronous JavaScript and XML(AJAX) • Web development technique for creating web applications • Makes web pages more responsive by exchanging small amounts of data • Allows the web page to change its content without refreshing the whole page • A web browser technology independent of web server software
  • 4. Benefits • Improves the user experience – Analyzing information typed into browser in real time – Provide a richer experience – Increases responsiveness of web pages • Improve bandwidth utilization – Only data which is required is retrieved from the server
  • 5. Real World Examples • Google Maps (http://maps.google.com/) (slidable maps) • My Yahoo! (http://my.yahoo.com/) (shuffling windows)
  • 6. How it works • AJAX runs in your browser • Works with asynchronous data transfers(HTTP requests) between the browser and the web server • Http requests are sent by javascript calls without having to submit a form • XML is commonly used as the format for receiving server data but plain text may be used as well
  • 7. 1 – XMLHttpRequest object • A page element must make a javascript call • The javascript function must create an XMLHttpRequest object which is used to contact the server • Javascript must determine whether the client is IE or Firefox • http = new ActiveXObject("Microsoft.XMLHTTP"); (IE) • http = new XMLHttpRequest(); (Mozilla)
  • 8. 2 - Sending the request • Once the XMLHttpRequest object has been created it must be set up to call the server • http.open("GET", serverurl, true); • http.onreadystatechange = jsMethodToHandleResponse; • http.send(null); • The code above utilizes the XMLHttpRequest object to contact the server and retrieve server data • When the response returns the javascript method jsMethodToHandleResponse can update the page
  • 9. 3 - Handling the Response • Implementation of the javascript method which will be used to handle the response (Event Handler) • function jsMethodToHandleResponse(str) • { • //simply take the response returned an update an html element with the returned value from the server • document.getElementById("result").innerHTML = str; • } • Now the page has communicated with the server without having to refresh the entire page
  • 10. readyState property • The XMLHttpRequest readyState property defines the current state of the XMLHttpRequest object • Possible values for the readyState • Usually we are usually only concerned with state 4 State Description 0 The request is not initialized 1 The request has been setup 2 The request has been submitted 3 The request is in process 4 The request is completed
  • 11. Sample Code • Simply unzip the sample code into a JSP Location and go to index.jsp • There are various examples that show some AJAX functionality • It is all JSP to make it easy to setup and easy to see the code. • The JSPs are generic enough to be easily to converted to other technologies (.NET or PHP)