M Ramya

2,592 views

Published on

Topic:Ajax
Date:21st August 2009

Published in: Education, Spiritual, Technology
2 Comments
1 Like
Statistics
Notes
  • I've made myself one, taking in a few ideas from yours and posted on the site....have mentioned your name.. :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • This one, I thought was one fair presentation...thank you..did help me :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
2,592
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
197
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

M Ramya

  1. 3. INDEX <ul><li>History of AJAX </li></ul><ul><li> What is AJAX ? </li></ul><ul><li> AJAX Introduction </li></ul><ul><li> Why AJAX is Important ? </li></ul><ul><li>AJAX XMLHttpRequest </li></ul><ul><li>AJAX Example </li></ul><ul><li>AJAX Browser Support </li></ul><ul><li>AJAX - The XMLHttpRequest Object </li></ul><ul><li>AJAX - Request a Serve </li></ul><ul><li>AJAX - The Server-Side Script </li></ul>end
  2. 4. History of AJAX On April 30, 1993, CERN announced that the World Wide Web would be free for anyone to use and the Web took off, jumping from 130 Web sites in 1993 , to over 100,000 in 1996 , to 11.5 billion sites in 2005 . The main protocol used on the Web is the Hypertext Transfer Protocol (HTTP). It's a patented open Internet request/response protocol intended to publish and receive HTML pages. The Web was never meant to be used for applications, only mass storage or linked content. Ever since the Web came out, developers have been struggling to get around the request/response sequence. Browser asynchronous hacks have been possible since 1996 , when Internet Explorer introduced the IFRAME tag HOME NEXT
  3. 5. Microsoft's Remoting Scripting or MSRS was introduced in 1998. This device was more elaborate than previous hack attempts and used JavaScript to communicate with a hidden Java applet that was in charge of the asynchronous communication. In 2002, Microsoft replaced Remoting Scripting with the XMLHttpRequest object, which was quickly copied by all the major browsers. Most modern browsers now implement Uniform Resource Identifier (URI), HTTP/1.1, HTML 4.01, Document Object Model (DOM), and JavaScript. This means that there is less need for conditional statements to apply different scripts depending on the browser. Historically, Web sites improved in user experience by implementing Dynamic HTML or DHTML, a method of combining HTML, JavaScript, Cascading Style Sheets (CSS), and Document Object Model (DOM) to interact with user events. PREV NEXT
  4. 6. AJAX is only a communication layer and does not include any visual elements. However, because AJAX, like DHTML, is based on JavaScript, it can achieve amazing results. The term AJAX was coined on February 18, 2005, by Jesse James Garret (Father of AJAX)in a short essay published a few days after Google released its Maps application. PREV NEXT
  5. 7. When Google launched its AJAX services, it gave AJAX awareness, trust, and credibility. IBM and a group of industry leaders announced on February 2006, an open source initiative to promote AJAX adoption. This initiative, known as OpenAjax , is supported by over 60 companies and organizations including BEA Systems, Borland, the Dojo Foundation, the Eclipse Foundation, Google, IBM, Laszlo Systems, Mozilla, Nexaweb, Novell, Openwave Systems, Oracle, Red Hat, Yahoo, Zend, and Zimbra . PREV HOME
  6. 8. <ul><li>What is AJAX ? </li></ul><ul><li>AJAX = Asynchronous JavaScript and XML. </li></ul><ul><li>AJAX is based on JavaScript and HTTP requests. </li></ul><ul><li>AJAX is a type of programming made popular in 2005 by Google (with Google Suggest). </li></ul><ul><li>AJAX is not a new programming language, but a new way to use existing standards. </li></ul><ul><li>AJAX is a group of interrelated web development techniques used on the client-side to create interactive web applications or rich Internet applications. </li></ul>HOME NEXT
  7. 9. <ul><li>With Ajax, web applications can retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page. </li></ul><ul><li>The use of Ajax has led to an increase in interactive animation on web pages and better quality of Web services due to the asynchronous mode. </li></ul><ul><li>Data is usually retrieved using the XMLHttpRequest object </li></ul>PREV HOME
  8. 10. AJAX Introduction <ul><li>AJAX is not a new programming language, but a new technique for creating better, faster, and more interactive web applications. </li></ul><ul><li>With AJAX, a JavaScript can communicate directly with the server, with the XMLHttpRequest object. With this object, a JavaScript can trade data with a web server, without reloading the page. </li></ul><ul><li>AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of whole pages. </li></ul>HOME NEXT
  9. 11. <ul><li>AJAX is based on the following web standards: </li></ul><ul><li>JavaScript </li></ul><ul><li>XML </li></ul><ul><li>HTML </li></ul><ul><li>CSS </li></ul><ul><li>AJAX applications are browser- and platform-independent </li></ul><ul><li>Internet-applications have many benefits over desktop applications; they can reach a larger audience, they are easier to install and support, and easier to develop. </li></ul><ul><li>With AJAX, Internet applications can be made richer and more user-friendly. </li></ul>PREV HOME
  10. 12. <ul><li>AJAX enables a much better user experience for Web sites and applications. </li></ul><ul><li>Developers can now provide user interfaces that are nearly as responsive and rich as more traditional Windows Forms applications while taking advantage of the Web's innate ease of deployment and heterogeneous, cross-platform nature. </li></ul><ul><li>These benefits have been shown to dramatically reduce software maintenance costs and increase its reach. You can use AJAX to only load the portions of pages that change, </li></ul>Why AJAX is Important ? HOME HOME
  11. 13. AJAX XMLHttpRequest <ul><li>To get or send information from/to a database or a file on the server with traditional JavaScript, you will have to make an HTML form, and a user will have to click the &quot;Submit&quot; button to send/get the information, wait for the server to respond, then a new page will load with the results. </li></ul><ul><li>Because the server returns a new page each time the user submits input, traditional web applications can run slowly and tend to be less user-friendly. </li></ul><ul><li>With AJAX, your JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object. </li></ul>HOME NEXT
  12. 14. PREV NEXT
  13. 15. <ul><li>With the XMLHttpRequest object, a web page can make a request to, and get a response from a web server - without reloading the page. </li></ul><ul><li>The user will stay on the same page, and he or she will not notice that scripts request pages, or send data to a server in the background. </li></ul><ul><li>By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded! </li></ul><ul><li>Google Suggest is using the XMLHttpRequest object to create a very dynamic web interface: When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions. </li></ul>PREV HOME
  14. 16. AJAX Example First AJAX application : To understand how AJAX works, we will create a small AJAX application. First we are going to create a standard HTML form with two input fields: Name and Time. The &quot;Name&quot; field will be filled out by the user, and the &quot;Time&quot; field will be filled out with AJAX. The HTML file will be named &quot;testAjax.htm&quot;, and it looks like this : <html> <body> <form name=&quot;myForm&quot;> Name: <input type=&quot;text&quot; name=&quot;username&quot; /> Time: <input type=&quot;text&quot; name=&quot;time&quot; /> </form> </body> </html> HOME NEXT
  15. 17. Output : PREV HOME
  16. 18. AJAX Browser Support <ul><li>The keystone of AJAX is the XMLHttpRequest object. </li></ul><ul><li>All new browsers use the built-in JavaScript XMLHttpRequest object to create an XMLHttpRequest object (IE5 and IE6 uses an ActiveXObject). </li></ul><ul><li>Let's update our &quot;testAjax.htm&quot; file with a JavaScript that creates an XMLHttpRequest object: </li></ul>HOME NEXT
  17. 19. <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> <form name=&quot;myForm&quot;> Name: <input type=&quot;text&quot; name=&quot;username&quot; /> Time: <input type=&quot;text&quot; name=&quot;time&quot; /> </form> </body> </html> PREV NEXT
  18. 20. <ul><li>Example explained </li></ul><ul><li>Create a variable named xmlhttp to hold the XMLHttpRequest object. </li></ul><ul><li>2. Try to create the XMLHttpRequest object with xmlhttp=new XMLHttpRequest(). </li></ul><ul><li>3. If that fails, try xmlhttp=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;). This is for IE6 and IE5. </li></ul><ul><li>4. If that fails too, the user has a very outdated browser, and will get an alert stating that the browser doesn't support XMLHTTP. </li></ul>PREV HOME
  19. 21. AJAX - The XMLHttpRequest Object <ul><li>Before sending data off to a server, we will look at three important properties of the XMLHttpRequest object. </li></ul><ul><li>The onreadystatechange property </li></ul><ul><li>After a request to a server, we need a function to receive the data returned from the server. </li></ul><ul><li>The onreadystatechange property stores the function that will process the response from a server. The function is stored in the property to be called automatically. </li></ul><ul><li>The following code sets the onreadystatechange property and stores an empty function inside it: </li></ul><ul><li>xmlhttp.onreadystatechange=function() { // We are going to write some code here } </li></ul>HOME NEXT
  20. 22. <ul><li>The readyState property </li></ul><ul><li>The readyState property holds the status of the server's response. </li></ul><ul><li>Each time the readyState property changes, the onreadystatechange function will be executed. </li></ul><ul><li>Possible values for the readyState property: </li></ul><ul><li>Add an If statement to the onreadystatechange function to test if the response is complete </li></ul><ul><li>xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4)   {   // Get data from the server's response   } } </li></ul>PREV NEXT 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
  21. 23. <ul><li>The responseText property </li></ul><ul><li>The data sent back from a server can be retrieved with the responseText property </li></ul><ul><li>Now, we want to set the value of the &quot;Time&quot; input field equal to responseText: </li></ul><ul><li>xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4)   {   document.myForm.time.value=xmlhttp.responseText;   } } </li></ul>PREV HOME
  22. 24. AJAX - Request a Server <ul><li>To send off a request to the server, we use the open() and send() methods. </li></ul><ul><li>The open() method takes three arguments. </li></ul><ul><li>The first argument defines which method to use when sending the request (GET or POST). </li></ul><ul><li>The second argument specifies the URL of the server-side script. </li></ul><ul><li>The third argument specifies that the request should be handled asynchronously. </li></ul><ul><li>The send() method sends the request off to the server. If we assume that the HTML and ASP file are in the same directory, the code would be: </li></ul><ul><li>xmlhttp.open(&quot;GET&quot;,&quot;time.asp&quot;,true); xmlhttp.send(null); </li></ul><ul><li>Now we must decide when the AJAX function should be executed. </li></ul>HOME NEXT
  23. 25. <ul><li>We will let the function run &quot;behind the scenes&quot; when a user types something in the &quot;Name&quot; field: </li></ul><ul><li><form name=&quot;myForm&quot;> Name: <input type=&quot;text&quot; name=&quot;username&quot; onkeyup=&quot;ajaxFunction();&quot; /> Time: <input type=&quot;text&quot; name=&quot;time&quot; /> </form> </li></ul><ul><li>Our updated &quot;testAjax.htm&quot; file now looks like this: </li></ul><ul><li><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;);   } </li></ul>PREV NEXT
  24. 26. else   {   alert(&quot;Your browser does not support XMLHTTP!&quot;);   } xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4)   {   document.myForm.time.value=xmlhttp.responseText;   } } xmlhttp.open(&quot;GET&quot;,&quot;time.asp&quot;,true); xmlhttp.send(null); } </script> <form name=&quot;myForm&quot;> Name: <input type=&quot;text&quot; name=&quot;username&quot; onkeyup=&quot;ajaxFunction();&quot; /> Time: <input type=&quot;text&quot; name=&quot;time&quot; /> </form> </body> </html> PREV HOME
  25. 27. AJAX - The Server-Side Script <ul><li>Now we are going to create the server-side script that displays the current time. </li></ul><ul><li>The responseText property will store the data returned from the server. Here we want to send back the current time. </li></ul><ul><li>The code in &quot;time.asp&quot; looks like this: </li></ul><ul><li><% response.expires=-1 response.write(time) %> </li></ul><ul><li>Note: The response.expires command sets how long time (in minutes) a page will be cached on a browser before it expires. If a user returns to the same page before it expires, the cached version is displayed. response.expires=-1 indicates that the page will never be cached. </li></ul>PREV NEXT
  26. 28. Referenced sites: http://www.w3schools.com http://www.infragistics.com http://java.sun.com http://www.trishalyn.com Presented By M.Ramya MCA III Year The End

×