• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Ajax
 

Ajax

on

  • 782 views

 

Statistics

Views

Total Views
782
Views on SlideShare
775
Embed Views
7

Actions

Likes
0
Downloads
15
Comments
0

1 Embed 7

http://bartercash.enfinet.com 7

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • AJAX – has taken IT industry by storm. It might turn out to be one of the most demanded thing/in thing and hence, a brief presentation to understand AJAX. Be it anything that we are learning, asking 6 key questions is very important to get an overall idea of the same. The questions being – What, Why, Who, How, When and Where. So let’s being with what is AJAX? – not a technology, not a product … but an approach taken to develop Web Applications.
  • Inorder to understand what is this approach all about … let us first seek to know what the current approach is … At present, for every user interaction, the entire web page is rebuild. Even if a part of the entire page needs to be changed … we land up reloading the entire page. Which leads to … network traffic … slow speed … and most importantly … user experience goes down … user has to wait for loading of images … controls … which had already been loaded once!!! This is what AJAX asks us not to do.

Ajax Ajax Presentation Transcript

  • AJAX – Asynchronous JavaScript and XML
  • What is AJAX ? Ajax is a set of client side technologies that provides asynchronous communication between user interfaces and web server. So the advantages of using Ajax are asynchronous communication, minimal data transfer and server is not overloaded with unnecessary load.
  • What problem does Ajax solve?
    • Unnecessary data transfers
    • Synchronous processing
    • Unnecessary processing by server
  • Unnecessary data is transferred between client and server. For instance, the whole page is posted and refreshed even when we want small data of the page to be refreshed.
    • Unnecessary data transfers
  • When a user requests for a page he has to wait until the complete round trip happens. In short, the request / response work on a synchronous model rather than asynchronous which makes user experience very difficult. How many times it has happened that you are requesting a page and you see the below screen…frustrating right.
    • Synchronous processing
  • Because we are posting unnecessary information to the server, the server is overloaded with unnecessary processing.
    • Unnecessary processing by server
  • Ajax Lifecycle
  • XmlHttpRequest ?
    • Client Side Component.
    • Must be instantiated before use.
    • Use open() method to connect and retrieve response from the specified URL.
    • Handle onreadystatechange Event.
  • XmlHttpRequest Component
    • Internet Explorer 5
    • Mozilla 1.0 – Netscape 7
    • Safari 1.2
    • Opera 7.6
    • Firefox
  • Let’s see some coding : <html> <head> <script language = &quot;javascript&quot;> function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject (&quot;Microsoft.XMLHTTP&quot;); } return null; }
  • Let’s see some coding : var xmlhttp; function showUser(str) { xmlhttp= GetXmlHttpObject(); if (xmlhttp==null) { alert (&quot;Browser does not support HTTP Request&quot;); return; } var url=&quot;getselected.php&quot;; url= url+&quot;?id=&quot;+str; xmlhttp.onreadystatechange= stateChanged; xmlhttp.open (&quot;GET“ ,url,true); xmlhttp.send(null); } 
  • Coding : PHP [getselected.php]
    • <?php
    • //Display Message
      • echo “This is Ajax with PHP “;
    • ?>
  • Coding: Javascript
    • function stateChanged()
    • {
    • if (xmlhttp.readyState==4)
    • {
    • document.getElementById(&quot;txtHint&quot;).innerHTML= xmlhttp.responseText;
    • }
    • }
    • - Continued
  • Coding: Javascript
    • </script>
    • </head>
    • <body>
    • <form>
    • Select a User:
    • <select name=&quot;users&quot; onChange=&quot;showUser(this.value)&quot;>
    • <option value=&quot;1&quot;>Peter Griffin</option>
    • <option value=&quot;2&quot;>Lois Griffin</option>
    • <option value=&quot;3&quot;>Glenn Quagmire</option>
    • </select>
    • </form>
    • <br />
    • <div id=&quot;txtHint&quot;><b>Person information will be listed here.</b></div>
    • </body>
    • </html>
  • Limitations of AJAX
    • JavaScript Implementations.
    • Debugging.
    • Security.
  • One of the well known tools in building an efficient Ajax based application is jQuery. This programming language is often used in developing plug-ins for JavaScript and Ajax based applications.
    • JQuery
  • <html> <head> <script src=&quot;jquery.js&quot; type=&quot;text/javascript&quot;></script> <script type=&quot;text/javascript&quot;> $(function() { $('#container-1').tabs(); }); </script> </head> <body> <h2>Simple Tabs</h2> <div id=&quot;container-1&quot;> <ul> <li><a href=&quot;#fragment-1&quot;><span>Tab1</span></a></li> <li><a href=&quot;#fragment-2&quot;><span>Tab2</span></a></li> <li><a href=&quot;#fragment-3&quot;><span>Tab3</span></a></li> </ul> -continued
    • Let’s see some coding using jquery
  • <ul> <li><a href=&quot;#fragment-1&quot;><span>Tab1</span></a></li> <li><a href=&quot;#fragment-2&quot;><span>Tab2</span></a></li> <li><a href=&quot;#fragment-3&quot;><span>Tab3</span></a></li> </ul> <div id=&quot;fragment-1&quot;> <p>First tab is active by default:</p> <pre><code>$(&#039;#container&#039;).tabs();</code></pre> </div> <div id=&quot;fragment-2&quot;> Some text goes here for tab2 </div> <div id=&quot;fragment-3&quot;> some more text for tab3</div> </div> </body> </html>
    • Let’s see some coding using jquery
  • Thank You