SlideShare ist ein Scribd-Unternehmen logo
1 von 11
AJAX
      AJAX stands for Asynchronous JavaScript And XML.
   Any server side technology that supports JavaScript also
                        supports AJAX.
AJAX is a browser technology, and is therefore independent of
                    web server platforms.
  AJAX is not a programming language, so you don’t have to
learn any new technology. AJAX can be implemented by using
  existing standards (JavaScript and XML) in a different way.
   AJAX uses HTTP requests for this. With AJAX, JavaScript
communicates directly with the server, through the JavaScript
           XMLHttpRequest object (XML over HTTP)
AJAX to request a data from the server we need


• 1. Create an XMLHttpRequest object.
• 2. Then using this object, request data from the server.
• 3. JavaScript will then monitor for the changing of state of the
  request.
• 4. If the response is successful, then the content from the
  data store requested will be returned as response (response
  can be in the form of a String or XML).
• 5. Use the response in your web page.
1.Create an XMLHttpRequest object


• JavaScript has a built-in XMLHttpRequest object
• For Internet Explorer use the ActiveXObject
var req;
                        XMLHttpRequest for all browsers                   :
if(window.XMLHttpRequest)
     {
           //For Firefox, Safari, Opera
           req = new XMLHttpRequest();
      }
else if(window.ActiveXObject)
      {
           //For IE 5
          req = new ActiveXObject(“Microsoft.XMLHTTP”);
      }
else if(window.ActiveXObject)
     {
         //For IE 6+
         req = new ActiveXObject(“Msxml2.XMLHTTP”);
     }
Else
    {
        //Error for an old browser
         alert(‘Your browser is not IE 5 or higher, or Firefox or Safari or Opera’);
     }
2. Request for a web page

• After creating the XMLHttpRequest we now need to send the web request
  using the open method. We also need to specify the HttpRequest method,
  GET or POST. Use the following code to send the request.
• Use the following code to send the request.
• req.open(“GET”,”somedata.php”);
• req.send(null);
• Here, req is the XMLHttpRequest object. It will request to the server for
  somedata.php using GET method. The open function also has a third
  parameter, an optional boolean parameter. You should set that to true :

• req.open(“GET”,”somedata.php”,true);
• req.send(null);

• Both of the above is correct.
3. Monitor for the response of the request


• For doing this you can assign a function to
  req.onreadystatechange (Here, req is the
  XMLHttpRequest object), like below.

• req.onreadystatechange=function()
  {
    if(req.readyState==4 && req.status == 200)
      {
         var resp = req.responseText;
      }
  }
like this



• req.onreadystatechange = handleResponse;
• function handleResponse()
   {
       if(req.readyState == 4 && req.status == 200)
        {
            //returned text from the PHP script
            var response = req.responseText;
         }
  }
• The readyState property holds the status of the server’s response.
  Each time the readyState changes, the onreadystatechange
  function will be executed. Here are the possible values for the
  readyState property:
• State Description
• 0 The request is not initialized
• 1 The request has been set up
• 2 The request has been sent
• 3 The request is in process
• 4 The request is complete

• And status is the status of the HTTP Request, like 500 Internal
  Server Error, 400 Bad Request, 401 Unauthorized, 403 Forbidden,
  404 Not Found etc. 200 means no error.
4. Get the response


• The response will be as string or as XML. The data sent back
  from the server can be retrieved with the responseText
  property as string. Use responseXML for getting the response
  as XML.
5. Use the response on your web page


• You can use the response you got from the XMLHttpRequest
  in your web page/application. You can either set a value of a
  text field or use the returned HTML from the web request as
  innerHTML for a <div></div> tag or <span></span> tag (See
  below for the implementation of this)
Life without dreams is purpose less


Zia Ur Rehman
BCS-6
2012

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Ajax
AjaxAjax
Ajax
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP 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
AJAXAJAX
AJAX
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
 
Overview of AJAX
Overview of AJAXOverview of AJAX
Overview of AJAX
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Jquery Ajax
Jquery AjaxJquery Ajax
Jquery Ajax
 

Ähnlich wie Ajax Technology (20)

Ajax
AjaxAjax
Ajax
 
Ajax Tuturial
Ajax TuturialAjax Tuturial
Ajax Tuturial
 
httprqstobj.ppt
httprqstobj.ppthttprqstobj.ppt
httprqstobj.ppt
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
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.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Xml http request
Xml http requestXml http request
Xml http request
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
ITI006En-AJAX
ITI006En-AJAXITI006En-AJAX
ITI006En-AJAX
 
Ajax
AjaxAjax
Ajax
 
AJAX Transport Layer
AJAX Transport LayerAJAX Transport Layer
AJAX Transport Layer
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
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
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 

Kürzlich hochgeladen

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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
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
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Kürzlich hochgeladen (20)

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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
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
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
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)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Ajax Technology

  • 1. AJAX AJAX stands for Asynchronous JavaScript And XML. Any server side technology that supports JavaScript also supports AJAX. AJAX is a browser technology, and is therefore independent of web server platforms. AJAX is not a programming language, so you don’t have to learn any new technology. AJAX can be implemented by using existing standards (JavaScript and XML) in a different way. AJAX uses HTTP requests for this. With AJAX, JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object (XML over HTTP)
  • 2. AJAX to request a data from the server we need • 1. Create an XMLHttpRequest object. • 2. Then using this object, request data from the server. • 3. JavaScript will then monitor for the changing of state of the request. • 4. If the response is successful, then the content from the data store requested will be returned as response (response can be in the form of a String or XML). • 5. Use the response in your web page.
  • 3. 1.Create an XMLHttpRequest object • JavaScript has a built-in XMLHttpRequest object • For Internet Explorer use the ActiveXObject
  • 4. var req; XMLHttpRequest for all browsers : if(window.XMLHttpRequest) { //For Firefox, Safari, Opera req = new XMLHttpRequest(); } else if(window.ActiveXObject) { //For IE 5 req = new ActiveXObject(“Microsoft.XMLHTTP”); } else if(window.ActiveXObject) { //For IE 6+ req = new ActiveXObject(“Msxml2.XMLHTTP”); } Else { //Error for an old browser alert(‘Your browser is not IE 5 or higher, or Firefox or Safari or Opera’); }
  • 5. 2. Request for a web page • After creating the XMLHttpRequest we now need to send the web request using the open method. We also need to specify the HttpRequest method, GET or POST. Use the following code to send the request. • Use the following code to send the request. • req.open(“GET”,”somedata.php”); • req.send(null); • Here, req is the XMLHttpRequest object. It will request to the server for somedata.php using GET method. The open function also has a third parameter, an optional boolean parameter. You should set that to true : • req.open(“GET”,”somedata.php”,true); • req.send(null); • Both of the above is correct.
  • 6. 3. Monitor for the response of the request • For doing this you can assign a function to req.onreadystatechange (Here, req is the XMLHttpRequest object), like below. • req.onreadystatechange=function() { if(req.readyState==4 && req.status == 200) { var resp = req.responseText; } }
  • 7. like this • req.onreadystatechange = handleResponse; • function handleResponse() { if(req.readyState == 4 && req.status == 200) { //returned text from the PHP script var response = req.responseText; } }
  • 8. • The readyState property holds the status of the server’s response. Each time the readyState changes, the onreadystatechange function will be executed. Here are the possible values for the readyState property: • State Description • 0 The request is not initialized • 1 The request has been set up • 2 The request has been sent • 3 The request is in process • 4 The request is complete • And status is the status of the HTTP Request, like 500 Internal Server Error, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found etc. 200 means no error.
  • 9. 4. Get the response • The response will be as string or as XML. The data sent back from the server can be retrieved with the responseText property as string. Use responseXML for getting the response as XML.
  • 10. 5. Use the response on your web page • You can use the response you got from the XMLHttpRequest in your web page/application. You can either set a value of a text field or use the returned HTML from the web request as innerHTML for a <div></div> tag or <span></span> tag (See below for the implementation of this)
  • 11. Life without dreams is purpose less Zia Ur Rehman BCS-6 2012