SlideShare une entreprise Scribd logo
1  sur  10
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)

Contenu connexe

Tendances

Stored-Procedures-Presentation
Stored-Procedures-PresentationStored-Procedures-Presentation
Stored-Procedures-Presentation
Chuck Walker
 
XStream Quick Start
XStream Quick StartXStream Quick Start
XStream Quick Start
Guo Albert
 
Repository design pattern in laravel
Repository design pattern in laravelRepository design pattern in laravel
Repository design pattern in laravel
Sameer Poudel
 

Tendances (20)

Dynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection PromisesDynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection Promises
 
Active Object Design Pattern
Active Object Design PatternActive Object Design Pattern
Active Object Design Pattern
 
Step types
Step typesStep types
Step types
 
Computers & Technology :: Extracting Data from an AJAX-enabled Web Site
Computers & Technology :: Extracting Data from an AJAX-enabled Web SiteComputers & Technology :: Extracting Data from an AJAX-enabled Web Site
Computers & Technology :: Extracting Data from an AJAX-enabled Web Site
 
Oracle Forms : Query Triggers
Oracle Forms : Query TriggersOracle Forms : Query Triggers
Oracle Forms : Query Triggers
 
Stored-Procedures-Presentation
Stored-Procedures-PresentationStored-Procedures-Presentation
Stored-Procedures-Presentation
 
Spring batch
Spring batchSpring batch
Spring batch
 
SQL Server Stored procedures
SQL Server Stored proceduresSQL Server Stored procedures
SQL Server Stored procedures
 
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
 
XStream Quick Start
XStream Quick StartXStream Quick Start
XStream Quick Start
 
Introduction to SoapUI day 2
Introduction to SoapUI day 2Introduction to SoapUI day 2
Introduction to SoapUI day 2
 
Repository design pattern in laravel
Repository design pattern in laravelRepository design pattern in laravel
Repository design pattern in laravel
 
Servlets - filter, listeners, wrapper, internationalization
Servlets -  filter, listeners, wrapper, internationalizationServlets -  filter, listeners, wrapper, internationalization
Servlets - filter, listeners, wrapper, internationalization
 
2310 b 07
2310 b 072310 b 07
2310 b 07
 
Exploring the details of APEX sessions
Exploring the details of APEX sessionsExploring the details of APEX sessions
Exploring the details of APEX sessions
 
Dev308
Dev308Dev308
Dev308
 
Spring batch
Spring batchSpring batch
Spring batch
 
7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task
 
Lecture13
Lecture13Lecture13
Lecture13
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 

En vedette

Ruby for PHP developers
Ruby for PHP developersRuby for PHP developers
Ruby for PHP developers
Max Titov
 

En vedette (7)

Ruby for PHP developers
Ruby for PHP developersRuby for PHP developers
Ruby for PHP developers
 
[HUBFORUM Paris] BuzzFeed Presents the native truth - Will Hayward
[HUBFORUM Paris] BuzzFeed Presents the native truth - Will Hayward[HUBFORUM Paris] BuzzFeed Presents the native truth - Will Hayward
[HUBFORUM Paris] BuzzFeed Presents the native truth - Will Hayward
 
Ajax Technology
Ajax TechnologyAjax Technology
Ajax Technology
 
121008 cbs hv bovern 2
121008 cbs hv bovern 2121008 cbs hv bovern 2
121008 cbs hv bovern 2
 
Multiquery optimization on spark
Multiquery optimization on sparkMultiquery optimization on spark
Multiquery optimization on spark
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 

Similaire à Ajax

Similaire à Ajax (20)

Ajax
AjaxAjax
Ajax
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Ajax Tuturial
Ajax TuturialAjax Tuturial
Ajax Tuturial
 
httprqstobj.ppt
httprqstobj.ppthttprqstobj.ppt
httprqstobj.ppt
 
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.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Ajax
AjaxAjax
Ajax
 
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
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
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
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Ajax

  • 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)