SlideShare a Scribd company logo
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

More Related Content

PPTX
What is Ajax technology?
PPTX
Ajax PPT
PPTX
Introduction to ajax
PPT
Ajax Ppt 1
PDF
Ajax Introduction Presentation
PPT
Ajax presentation
PPT
What is Ajax technology?
Ajax PPT
Introduction to ajax
Ajax Ppt 1
Ajax Introduction Presentation
Ajax presentation

What's hot (20)

PPT
Asynchronous JavaScript & XML (AJAX)
PPTX
Ajax
PPT
PHP - Introduction to PHP AJAX
PPT
Using Ajax In Domino Web Applications
PPT
Ajax Presentation
PDF
Introduction to ajax
PPT
An Introduction to Ajax Programming
PPT
Ajax and PHP
PPT
Ajax Ppt
PPT
Introduction to ajax
PPTX
Introduction to ajax
PPTX
Overview of AJAX
PPTX
Ajax presentation
PPT
PPT
DOCX
Jquery Ajax
Asynchronous JavaScript & XML (AJAX)
Ajax
PHP - Introduction to PHP AJAX
Using Ajax In Domino Web Applications
Ajax Presentation
Introduction to ajax
An Introduction to Ajax Programming
Ajax and PHP
Ajax Ppt
Introduction to ajax
Introduction to ajax
Overview of AJAX
Ajax presentation
Jquery Ajax
Ad

Similar to Ajax Technology (20)

PPT
PPT
Web Programming using Asynchronous JavaX
PPT
Ajax Tuturial
PPT
httprqstobj.ppt
PPTX
AJAX.pptx
PDF
Ajax and xml
PPTX
Unit-5.pptx
PPTX
AJAX.pptx
PPT
Xml http request
PPTX
HSHDGDGDHDYDUDUDUDHDHDHSHAHAHSHSBDHDHDHDHDHD
PPT
Ajax tutorial by bally chohan
PDF
ITI006En-AJAX
PDF
AJAX Transport Layer
PDF
PPT
PDF
Core Java tutorial at Unit Nexus
PPT
Web Programming using Asynchronous JavaX
Ajax Tuturial
httprqstobj.ppt
AJAX.pptx
Ajax and xml
Unit-5.pptx
AJAX.pptx
Xml http request
HSHDGDGDHDYDUDUDUDHDHDHSHAHAHSHSBDHDHDHDHDHD
Ajax tutorial by bally chohan
ITI006En-AJAX
AJAX Transport Layer
Core Java tutorial at Unit Nexus
Ad

Recently uploaded (20)

PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Cloud computing and distributed systems.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Electronic commerce courselecture one. Pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Network Security Unit 5.pdf for BCA BBA.
DOCX
The AUB Centre for AI in Media Proposal.docx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Weekly Chronicles - August'25 Week I
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Understanding_Digital_Forensics_Presentation.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Electronic commerce courselecture one. Pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Empathic Computing: Creating Shared Understanding
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Network Security Unit 5.pdf for BCA BBA.
The AUB Centre for AI in Media Proposal.docx

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