SlideShare una empresa de Scribd logo
1 de 10
AJAX The basics
WEB
•Client - Server
Web ServerWeb Browser SQL Server
TCP/IPInternet (HTTP)
Simplified Diagram
HTTP
•Stateless protocol (ignore session and viewstate)
•Serves entire state (page?) to browser every time
•Postback ENTIRE PAGE to page form (submit button)
•How can the browser communicate with server without Postback?
AJAX?
•Microsoft invented XMLHttpRequest Objects
•ActiveX object before IE7 ActiveXObject("Msxml2.XMLHTTP")
•XMLHttpRequest Calls should be asynchronous
•Asynchronous Javascript And XML
AJAX
•Requests cannot be cross domain (ignore CORS)
•Browser can make requests without reloading entire page (client side)
•Talks to server through XHR (XMLHttpRequest)
•XHR can pass more than just XML
CHEAT SHEET
•Create XHR Object
•Call xhr.Open pass “calling method”, url, async (true, false),
username, pw
•Check readyState – returned 4 means returned with data
AJAX
•Create wrapper function
function createXMLHttpRequest() {
try {
return new XMLHttpRequest();
} catch(e) {}
try {
return new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {}
alert("XMLHttpRequest not supported");
return null;
}
AJAX
•Call createXMLHttpRequest
var xhReq = createXMLHttpRequest();
xhReq.open("GET", url, true);
xhReq.onreadystatechange =
function {
if (xhReq.readyState != 4) { return; }
var serverResponse = xhReq.responseText;
//var serverResponse = xhReq.responseXML;
}
xhReq.send(null);
API SUMMARY
•XMLHttpRequest Object Properties
•onreadystatechange: Callback function
•readyState: State of the request cycle
•responseText: Text response from the server
•responseXML: XML response from the server
•status: HTTP response code received from the server
•statusText: HTTP response code description received from the server
API SUMMARY
•XMLHttpRequest Object Methods
•abort(): Stops the request and resets its readyState back to zero.
•getAllResponseHeaders(): Returns a string of all response headers, separated by a newline as in
the original message.
•getResponseHeader(headerField): Returns the value for a particular header field.
•open(requestMethod, url, asynchronousFlag, username, password): Prepares XMLHttpRequest.
Only the first two parameters are required. username and password can be used for
authentication.
•send(bodyContent): Sends the message along with specified body content (null if no body
content is to be sent, e.g. for GET requests).
•setRequestHeader(headerField, headerValue): Sets a request header.

Más contenido relacionado

La actualidad más candente

Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajaxPihu Goel
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applicationsdominion
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slidesSmithss25
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentationengcs2008
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajaxRaja V
 
Learn Ajax here
Learn Ajax hereLearn Ajax here
Learn Ajax herejarnail
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Adnan Sohail
 
Languages and tools for web programming
Languages and tools for web  programmingLanguages and tools for web  programming
Languages and tools for web programmingAlamelu
 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programminghchen1
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-CJuio Barros
 
What is Ajax technology?
What is Ajax technology?What is Ajax technology?
What is Ajax technology?JavaTpoint.Com
 
mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.Oleg Shanyuk
 

La actualidad más candente (20)

Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Learn Ajax here
Learn Ajax hereLearn Ajax here
Learn Ajax here
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Languages and tools for web programming
Languages and tools for web  programmingLanguages and tools for web  programming
Languages and tools for web programming
 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-C
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
What is Ajax technology?
What is Ajax technology?What is Ajax technology?
What is Ajax technology?
 
mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
Grails and Ajax
Grails and AjaxGrails and Ajax
Grails and Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 

Destacado

Texto 7 educar la visión artística cap 8
Texto 7 educar la visión artística cap 8Texto 7 educar la visión artística cap 8
Texto 7 educar la visión artística cap 8Peteca Indiaca
 
Evaluation Questions
Evaluation QuestionsEvaluation Questions
Evaluation Questionsjudymilner001
 
Studying in the profitability of kalinganagar integrated greenfield
Studying in the profitability of kalinganagar integrated greenfieldStudying in the profitability of kalinganagar integrated greenfield
Studying in the profitability of kalinganagar integrated greenfieldBismay Mishra
 
Kamishibai :A princesa e o chícharo
Kamishibai :A princesa e o chícharoKamishibai :A princesa e o chícharo
Kamishibai :A princesa e o chícharomariapousa
 
Teoría emergente
Teoría emergenteTeoría emergente
Teoría emergentev_idel
 
Embedding graduate attributes in a mathematics programme
Embedding graduate attributes in a mathematics programme Embedding graduate attributes in a mathematics programme
Embedding graduate attributes in a mathematics programme Rita Ndagire Kizito
 
KOL Relationship Management in Pharma & Devices - Workshop Highlights
KOL Relationship Management in Pharma & Devices - Workshop HighlightsKOL Relationship Management in Pharma & Devices - Workshop Highlights
KOL Relationship Management in Pharma & Devices - Workshop HighlightsAnup Soans
 
OAAA TAB National Convention
OAAA TAB National ConventionOAAA TAB National Convention
OAAA TAB National ConventionMark Boidman
 
Bastrop current land use plan
Bastrop current land use planBastrop current land use plan
Bastrop current land use planKim Mitchell
 

Destacado (15)

Urinary flash cards
Urinary flash cardsUrinary flash cards
Urinary flash cards
 
Texto 7 educar la visión artística cap 8
Texto 7 educar la visión artística cap 8Texto 7 educar la visión artística cap 8
Texto 7 educar la visión artística cap 8
 
Evaluation Questions
Evaluation QuestionsEvaluation Questions
Evaluation Questions
 
Culturas Antiguas.
  Culturas Antiguas.  Culturas Antiguas.
Culturas Antiguas.
 
Studying in the profitability of kalinganagar integrated greenfield
Studying in the profitability of kalinganagar integrated greenfieldStudying in the profitability of kalinganagar integrated greenfield
Studying in the profitability of kalinganagar integrated greenfield
 
Kamishibai :A princesa e o chícharo
Kamishibai :A princesa e o chícharoKamishibai :A princesa e o chícharo
Kamishibai :A princesa e o chícharo
 
La creatividad, ¿de quien depende?
La creatividad, ¿de quien depende?La creatividad, ¿de quien depende?
La creatividad, ¿de quien depende?
 
Teoría emergente
Teoría emergenteTeoría emergente
Teoría emergente
 
Embedding graduate attributes in a mathematics programme
Embedding graduate attributes in a mathematics programme Embedding graduate attributes in a mathematics programme
Embedding graduate attributes in a mathematics programme
 
KOL Relationship Management in Pharma & Devices - Workshop Highlights
KOL Relationship Management in Pharma & Devices - Workshop HighlightsKOL Relationship Management in Pharma & Devices - Workshop Highlights
KOL Relationship Management in Pharma & Devices - Workshop Highlights
 
Trabajos extraclase
Trabajos extraclaseTrabajos extraclase
Trabajos extraclase
 
Comodin
ComodinComodin
Comodin
 
OAAA TAB National Convention
OAAA TAB National ConventionOAAA TAB National Convention
OAAA TAB National Convention
 
TueNight
TueNightTueNight
TueNight
 
Bastrop current land use plan
Bastrop current land use planBastrop current land use plan
Bastrop current land use plan
 

Similar a AJAX (20)

Ajax
AjaxAjax
Ajax
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Synapseindia dot net development web applications with ajax
Synapseindia dot net development  web applications with ajaxSynapseindia dot net development  web applications with ajax
Synapseindia dot net development web applications with ajax
 
ITI006En-AJAX
ITI006En-AJAXITI006En-AJAX
ITI006En-AJAX
 
javaScript and jQuery
javaScript and jQueryjavaScript and jQuery
javaScript and jQuery
 
Ajax
AjaxAjax
Ajax
 
AJAX
AJAXAJAX
AJAX
 
Ajax
AjaxAjax
Ajax
 
WEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptxWEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptx
 
Ajax
AjaxAjax
Ajax
 
WebSocket
WebSocketWebSocket
WebSocket
 
Introduction to AJAX
Introduction to AJAXIntroduction to AJAX
Introduction to AJAX
 
Ajax introduction
Ajax introductionAjax introduction
Ajax introduction
 
Ajax workshop
Ajax workshopAjax workshop
Ajax workshop
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
Ajax Tuturial
Ajax TuturialAjax Tuturial
Ajax Tuturial
 
Ajax
AjaxAjax
Ajax
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
 

AJAX

  • 2. WEB •Client - Server Web ServerWeb Browser SQL Server TCP/IPInternet (HTTP) Simplified Diagram
  • 3. HTTP •Stateless protocol (ignore session and viewstate) •Serves entire state (page?) to browser every time •Postback ENTIRE PAGE to page form (submit button) •How can the browser communicate with server without Postback?
  • 4. AJAX? •Microsoft invented XMLHttpRequest Objects •ActiveX object before IE7 ActiveXObject("Msxml2.XMLHTTP") •XMLHttpRequest Calls should be asynchronous •Asynchronous Javascript And XML
  • 5. AJAX •Requests cannot be cross domain (ignore CORS) •Browser can make requests without reloading entire page (client side) •Talks to server through XHR (XMLHttpRequest) •XHR can pass more than just XML
  • 6. CHEAT SHEET •Create XHR Object •Call xhr.Open pass “calling method”, url, async (true, false), username, pw •Check readyState – returned 4 means returned with data
  • 7. AJAX •Create wrapper function function createXMLHttpRequest() { try { return new XMLHttpRequest(); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {} alert("XMLHttpRequest not supported"); return null; }
  • 8. AJAX •Call createXMLHttpRequest var xhReq = createXMLHttpRequest(); xhReq.open("GET", url, true); xhReq.onreadystatechange = function { if (xhReq.readyState != 4) { return; } var serverResponse = xhReq.responseText; //var serverResponse = xhReq.responseXML; } xhReq.send(null);
  • 9. API SUMMARY •XMLHttpRequest Object Properties •onreadystatechange: Callback function •readyState: State of the request cycle •responseText: Text response from the server •responseXML: XML response from the server •status: HTTP response code received from the server •statusText: HTTP response code description received from the server
  • 10. API SUMMARY •XMLHttpRequest Object Methods •abort(): Stops the request and resets its readyState back to zero. •getAllResponseHeaders(): Returns a string of all response headers, separated by a newline as in the original message. •getResponseHeader(headerField): Returns the value for a particular header field. •open(requestMethod, url, asynchronousFlag, username, password): Prepares XMLHttpRequest. Only the first two parameters are required. username and password can be used for authentication. •send(bodyContent): Sends the message along with specified body content (null if no body content is to be sent, e.g. for GET requests). •setRequestHeader(headerField, headerValue): Sets a request header.