SlideShare ist ein Scribd-Unternehmen logo
1 von 16
AJAX BY, NIRMAL FELIX.K
What is Ajax? Ajax stands “A”: Asynchronous,”JA”: JavaScript”X”: XML. It is a group of (JavaScript and Xml) interrelated web development techniques used on the client  side to create interactive web application. Any server side technology that supports  JavaScript also supports Ajax. •  Foundation purpose of Ajax not to giving the output, but is to provide a simple and  standard means/output for a web page to communicate with the server without doing a complete page refresh. •  Ajax programming is introduced in 2005 by Google.
Technology used in Ajax Ajax as a combination of set of technologies. Use of Ajax is combination is of four things - 1: HTML/Xhtml, 2: JAVASCRIPT, 3: XML, 4: CSS. 2. JAVASCRIPT(ECMA Script) used for the local processing and  DOM (Document Object model) data access inside the page or access elements of  XML file read on the server. 3. Asynchronous data retrieval with XMLHttpRequest object.
Drawbacks of Ajax Apart from the benefits Ajax also have some drawback which to be kept in mind while learning it: •  If JavaScript is not activated, Ajax can't works. •  Another issue emerging from the dynamic nature of AJAX is a lack of interaction with search engines, Since data to display are loaded dynamically, they are not part  of the page, and the keywords inside are not viewed by search engines. •  The back button may be deactivated. •  It usually requires more development time to build an application using AJAX than  using other approaches. •  Another issue with JavaScript is that you have to consider what to do when a user  has disabled JavaScript support within their browser. This requires extra development  time to deliver an alternative solution. •  Data is loaded asynchronously without a page reload, so no page access is  recorded in the browser history.
AJAX: getting started Elements(Technologies) used in Ajax: Before Starting Ajax you should have the knowledge about the following things – 1-HTML 2-JAVASCRIPT and xml 3-PHP and little bit of the xml concepts. Before we explain anything about ajax, you should know how Ajax work, the main  magic behind Ajax is “javascript” and “XMLHTTPRequest Object” .
For creating your first Ajax based application, you should have the following things: 1: A front-end page (HTML page) 2: Php script 3: Xml Script HTML page: To begin with your first example, you have to prepare your first page it could be simply a scripting language like HTML, page containing the html tags, which is to be displayed. Html is used to display the data. PHP script: However your backend page have dynamic scripting language, which here we use as php language, which is used for querying a database. Basically it could be the anything  which requires server access which accept clients data, these languages are Php and Asp. An another script is used in the front end script called “XML” script.
Xml Basic: What is xml? It is necessary for you to know about the xml. What is it? And how it works? •  Basically Xml is shorts for Extensible Markup Language. •  It is a Meta language which is used to define other languages. •  It is used for storing and transporting the data. •  It does not similar to HTML because html was designed to display the data and XML is used to describe the data. •  XML is used to aid the exchange of data. •  The data is defined in the language in the structured way. •  Tags used in the xml are not predefined, as in html. XML, which represents the data passed between the server and client. So the points explained above are helpful for you to understanding xml.
JavaScript: It is not only the client-side scripting language that can be used for implementing an  Ajax application. Other languages such as VBScript are also capable of the required  functionality. JavaScript that allows for interaction with the browser and responding to events. XMLHttpRequest Object: Use XMLHttpRequest objects for browser-server communication JavaScript that allows for interaction with the browser and responding to events, XMLHttpRequest object is used for asynchronously exchanging the XML data  between the client and the server.
Creating the object: The following Example shown here demonstrates how to create and use the XMLHttpRequest object: This object is basically generated for all modern browsers like mozilla, safari  including IE7. Example: var reqObj=new XMLHttpRequest(); The object that is shown below is generated for IE5 and IE6. For the ActiveX branch , pass the name of the object to the ActiveX constructor: Example: var reqObj =new ActiveXObject ("Microsoft.XMLHTTP");
AJAX Request Introduction: Ajax sends a request to the server with following some method, the methods are  “ open()” and “send()”, the open method uses three augments, first is method type,  second is defined the url of the server side script and the third one is specifies that the  request should be handled asynchronously and the send method is sends the request  off to the server. The format of the open and send method are: xmlhttp.open("GET","validate.php",true); xmlhttp.send(null); It Initiates and process an ajax request. It simply allows to interact with the server. Use: new Ajax.Request(url[, options])
Actually this object is made for wrapping an instance of XMLHttpRequest and provides the facilities for setting function that are called before a request is made and after a  request returns. This is made for handling the server response. Point to be remember that whenever an Ajax request is sent to the server, a special header named “X-Requested-With” with a value of XMLHttpRequest is attached to the request. Example: function ajaxReq() { return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')); } IT would be very clear on seeing the code that, if the function return true then you  received an ajax request otherwise return a normal request on receiving false.
Ajax Working With browser Ajax unfortunately doesn’t have same code for all browser, it has little bit different for all the browser. The keystone of Ajax is XMLHttpRequest object. And it will be very necessary for you to know about the XMLHttpObject, how it makes all browser compactible with the code. <html> <body> <script type=&quot;text/javascript&quot;> function ajaxFunction() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE6, IE5 xmlhttp=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); } else { alert(&quot;Your browser does not support XMLHTTP!&quot;); } } </script>
Explaination: In the above javascript code, we try three times to make this XMLhttpRequest Object.  Creation of the object is done with the try catch block, the try catch block works as basically it  attempts to try a piece of code and if that piece causes the “error” it catches the error. 1.If you can see the code above you can notice that we first create a variable called xmlhttp to  hold the XMLHttpRequest object. 2.Then next step is to creating the object XMLHttpRequest object. As xmlhttp= new XMLHttpRequest() 3.If the above code fails, try xmlhttp = new ActiveXObject (“Microsoft XMLHTTP). It is used for IE6  and IE5. 4.If that one is also doesn’t work, the it means that the user uses very outdated browser,  so that the browser doesn’t support XMLHTTP. Note: The code above can be used every time you need to create an XMLHttpRequest object,  so just copy and paste it every time you want to use Ajax.
AJAX XMLHttpRequest: Introduction Ajax uses XMLHttpRequest objects for browser-server communication.  The mechanism for sending data to and retrieving data from the server with Ajax  is the XMLHttpRequest object. XMLHttpRequest has an important role in the AJAX web development technique.  It has been used by many websites to implement attractive and dynamic web applications. XMLHttpRequest can be used inside a web browser scripting language(Like JavaScript) , to send an HTTP or an HTTPS request directly to a web server and load the server  response data directly back into the scripting language.
It contains some informative values or a string, that is to be send at client side and be processed by the server. var url = &quot;test.php?uname=user&id=&quot; + escape(field.value); var  reqobj; // global variable to hold request object function loadXMLDocument(url, params) { if(window.XMLHttpRequest) { try { reqobj = new XMLHttpRequest();  // creation of XMLHttpRequest object } catch(e) { reqobj = false; } } else if(window.ActiveXObject) { try { reqobj = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;); } catch(e) { try { reqobj = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); } catch(e) { reqobj = false; } } } if(reqobj) { reqobj.onreadystatechange = processReqChange; return true; } return false; }
Creating an XMLHTTPRequest object: For Better use of ajax we must have to initialize the XMLHttpRequest object, use of that is very simple in most browsers, but it becomes  little bit complex, when we try to use the IE 5 and 6. Explanation If you review the above code, you can see that, The funchtion LoadXMLDocument accepts two parameter, first one be the url (server location) of the server side script which is being called and the second one is the variable to pass to the script. The script looks like as: <script type=&quot;text/javascript&quot; src=&quot;js/xmlhttp.js&quot;></script> <script type=&quot;text/javascript&quot;> var params = 'x=' + encodeURIComponent(input) + '&goal=' +  encodeURIComponent(goal); loadXMLDoc('/scripts/testscript.php', params); </script> This is the script reside in the path scripts/testscripts.php, it have two parameters, namely are “x”, “goal”

Weitere ähnliche Inhalte

Was ist angesagt? (19)

Apache
ApacheApache
Apache
 
Security in php
Security in phpSecurity in php
Security in php
 
Apache Presentation
Apache PresentationApache Presentation
Apache Presentation
 
Apache Server Tutorial
Apache Server TutorialApache Server Tutorial
Apache Server Tutorial
 
Apache Web Server Setup 3
Apache Web Server Setup 3Apache Web Server Setup 3
Apache Web Server Setup 3
 
Apache Presentation
Apache PresentationApache Presentation
Apache Presentation
 
4 Basic PHP
4 Basic PHP4 Basic PHP
4 Basic PHP
 
Apache error
Apache errorApache error
Apache error
 
Apache Tutorial
Apache TutorialApache Tutorial
Apache Tutorial
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
Apache Web Server Setup 1
Apache Web Server Setup 1Apache Web Server Setup 1
Apache Web Server Setup 1
 
Apache Web Server Setup 4
Apache Web Server Setup 4Apache Web Server Setup 4
Apache Web Server Setup 4
 
ASP.NET WEB API
ASP.NET WEB APIASP.NET WEB API
ASP.NET WEB API
 
Apache web server
Apache web serverApache web server
Apache web server
 
Php intro
Php introPhp intro
Php intro
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
 
Servlets
ServletsServlets
Servlets
 
4.4 PHP Session
4.4 PHP Session4.4 PHP Session
4.4 PHP Session
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 

Ähnlich wie Ajax (20)

PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
AJAX
AJAXAJAX
AJAX
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
 
Ajax
AjaxAjax
Ajax
 
ajax_pdf
ajax_pdfajax_pdf
ajax_pdf
 
ajax_pdf
ajax_pdfajax_pdf
ajax_pdf
 
M Ramya
M RamyaM Ramya
M Ramya
 
25250716 seminar-on-ajax text
25250716 seminar-on-ajax text25250716 seminar-on-ajax text
25250716 seminar-on-ajax text
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
mukesh
mukeshmukesh
mukesh
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 

Mehr von NIRMAL FELIX

Mehr von NIRMAL FELIX (6)

Mobile phones
Mobile phonesMobile phones
Mobile phones
 
php basics
php basicsphp basics
php basics
 
Html tag
Html tagHtml tag
Html tag
 
My resume
My resumeMy resume
My resume
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
Linux50commands
Linux50commandsLinux50commands
Linux50commands
 

Kürzlich hochgeladen

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Kürzlich hochgeladen (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 

Ajax

  • 1. AJAX BY, NIRMAL FELIX.K
  • 2. What is Ajax? Ajax stands “A”: Asynchronous,”JA”: JavaScript”X”: XML. It is a group of (JavaScript and Xml) interrelated web development techniques used on the client side to create interactive web application. Any server side technology that supports JavaScript also supports Ajax. • Foundation purpose of Ajax not to giving the output, but is to provide a simple and standard means/output for a web page to communicate with the server without doing a complete page refresh. • Ajax programming is introduced in 2005 by Google.
  • 3. Technology used in Ajax Ajax as a combination of set of technologies. Use of Ajax is combination is of four things - 1: HTML/Xhtml, 2: JAVASCRIPT, 3: XML, 4: CSS. 2. JAVASCRIPT(ECMA Script) used for the local processing and DOM (Document Object model) data access inside the page or access elements of XML file read on the server. 3. Asynchronous data retrieval with XMLHttpRequest object.
  • 4. Drawbacks of Ajax Apart from the benefits Ajax also have some drawback which to be kept in mind while learning it: • If JavaScript is not activated, Ajax can't works. • Another issue emerging from the dynamic nature of AJAX is a lack of interaction with search engines, Since data to display are loaded dynamically, they are not part of the page, and the keywords inside are not viewed by search engines. • The back button may be deactivated. • It usually requires more development time to build an application using AJAX than using other approaches. • Another issue with JavaScript is that you have to consider what to do when a user has disabled JavaScript support within their browser. This requires extra development time to deliver an alternative solution. • Data is loaded asynchronously without a page reload, so no page access is recorded in the browser history.
  • 5. AJAX: getting started Elements(Technologies) used in Ajax: Before Starting Ajax you should have the knowledge about the following things – 1-HTML 2-JAVASCRIPT and xml 3-PHP and little bit of the xml concepts. Before we explain anything about ajax, you should know how Ajax work, the main magic behind Ajax is “javascript” and “XMLHTTPRequest Object” .
  • 6. For creating your first Ajax based application, you should have the following things: 1: A front-end page (HTML page) 2: Php script 3: Xml Script HTML page: To begin with your first example, you have to prepare your first page it could be simply a scripting language like HTML, page containing the html tags, which is to be displayed. Html is used to display the data. PHP script: However your backend page have dynamic scripting language, which here we use as php language, which is used for querying a database. Basically it could be the anything which requires server access which accept clients data, these languages are Php and Asp. An another script is used in the front end script called “XML” script.
  • 7. Xml Basic: What is xml? It is necessary for you to know about the xml. What is it? And how it works? • Basically Xml is shorts for Extensible Markup Language. • It is a Meta language which is used to define other languages. • It is used for storing and transporting the data. • It does not similar to HTML because html was designed to display the data and XML is used to describe the data. • XML is used to aid the exchange of data. • The data is defined in the language in the structured way. • Tags used in the xml are not predefined, as in html. XML, which represents the data passed between the server and client. So the points explained above are helpful for you to understanding xml.
  • 8. JavaScript: It is not only the client-side scripting language that can be used for implementing an Ajax application. Other languages such as VBScript are also capable of the required functionality. JavaScript that allows for interaction with the browser and responding to events. XMLHttpRequest Object: Use XMLHttpRequest objects for browser-server communication JavaScript that allows for interaction with the browser and responding to events, XMLHttpRequest object is used for asynchronously exchanging the XML data between the client and the server.
  • 9. Creating the object: The following Example shown here demonstrates how to create and use the XMLHttpRequest object: This object is basically generated for all modern browsers like mozilla, safari including IE7. Example: var reqObj=new XMLHttpRequest(); The object that is shown below is generated for IE5 and IE6. For the ActiveX branch , pass the name of the object to the ActiveX constructor: Example: var reqObj =new ActiveXObject (&quot;Microsoft.XMLHTTP&quot;);
  • 10. AJAX Request Introduction: Ajax sends a request to the server with following some method, the methods are “ open()” and “send()”, the open method uses three augments, first is method type, second is defined the url of the server side script and the third one is specifies that the request should be handled asynchronously and the send method is sends the request off to the server. The format of the open and send method are: xmlhttp.open(&quot;GET&quot;,&quot;validate.php&quot;,true); xmlhttp.send(null); It Initiates and process an ajax request. It simply allows to interact with the server. Use: new Ajax.Request(url[, options])
  • 11. Actually this object is made for wrapping an instance of XMLHttpRequest and provides the facilities for setting function that are called before a request is made and after a request returns. This is made for handling the server response. Point to be remember that whenever an Ajax request is sent to the server, a special header named “X-Requested-With” with a value of XMLHttpRequest is attached to the request. Example: function ajaxReq() { return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')); } IT would be very clear on seeing the code that, if the function return true then you received an ajax request otherwise return a normal request on receiving false.
  • 12. Ajax Working With browser Ajax unfortunately doesn’t have same code for all browser, it has little bit different for all the browser. The keystone of Ajax is XMLHttpRequest object. And it will be very necessary for you to know about the XMLHttpObject, how it makes all browser compactible with the code. <html> <body> <script type=&quot;text/javascript&quot;> function ajaxFunction() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE6, IE5 xmlhttp=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); } else { alert(&quot;Your browser does not support XMLHTTP!&quot;); } } </script>
  • 13. Explaination: In the above javascript code, we try three times to make this XMLhttpRequest Object. Creation of the object is done with the try catch block, the try catch block works as basically it attempts to try a piece of code and if that piece causes the “error” it catches the error. 1.If you can see the code above you can notice that we first create a variable called xmlhttp to hold the XMLHttpRequest object. 2.Then next step is to creating the object XMLHttpRequest object. As xmlhttp= new XMLHttpRequest() 3.If the above code fails, try xmlhttp = new ActiveXObject (“Microsoft XMLHTTP). It is used for IE6 and IE5. 4.If that one is also doesn’t work, the it means that the user uses very outdated browser, so that the browser doesn’t support XMLHTTP. Note: The code above can be used every time you need to create an XMLHttpRequest object, so just copy and paste it every time you want to use Ajax.
  • 14. AJAX XMLHttpRequest: Introduction Ajax uses XMLHttpRequest objects for browser-server communication. The mechanism for sending data to and retrieving data from the server with Ajax is the XMLHttpRequest object. XMLHttpRequest has an important role in the AJAX web development technique. It has been used by many websites to implement attractive and dynamic web applications. XMLHttpRequest can be used inside a web browser scripting language(Like JavaScript) , to send an HTTP or an HTTPS request directly to a web server and load the server response data directly back into the scripting language.
  • 15. It contains some informative values or a string, that is to be send at client side and be processed by the server. var url = &quot;test.php?uname=user&id=&quot; + escape(field.value); var reqobj; // global variable to hold request object function loadXMLDocument(url, params) { if(window.XMLHttpRequest) { try { reqobj = new XMLHttpRequest(); // creation of XMLHttpRequest object } catch(e) { reqobj = false; } } else if(window.ActiveXObject) { try { reqobj = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;); } catch(e) { try { reqobj = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); } catch(e) { reqobj = false; } } } if(reqobj) { reqobj.onreadystatechange = processReqChange; return true; } return false; }
  • 16. Creating an XMLHTTPRequest object: For Better use of ajax we must have to initialize the XMLHttpRequest object, use of that is very simple in most browsers, but it becomes little bit complex, when we try to use the IE 5 and 6. Explanation If you review the above code, you can see that, The funchtion LoadXMLDocument accepts two parameter, first one be the url (server location) of the server side script which is being called and the second one is the variable to pass to the script. The script looks like as: <script type=&quot;text/javascript&quot; src=&quot;js/xmlhttp.js&quot;></script> <script type=&quot;text/javascript&quot;> var params = 'x=' + encodeURIComponent(input) + '&goal=' + encodeURIComponent(goal); loadXMLDoc('/scripts/testscript.php', params); </script> This is the script reside in the path scripts/testscripts.php, it have two parameters, namely are “x”, “goal”