Docsity

Introduction to Ajax Technology, Lecture notes of Web Application Development

Toggle sidebar
bg1
What is AJAX ?
•Asynchronous Javascript and XML.
•Not a stand-alone language or technology.
•It is a technique that combines a set of
known technologies in order to create faster
and more user friendly web pages.
•It is a client side technology.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Introduction to Ajax Technology and more Lecture notes Web Application Development in PDF only on Docsity!

What is AJAX?

  • (^) Asynchronous Javascript and XML.
  • (^) Not a stand-alone language or technology.
  • (^) It is a technique that combines a set of known technologies in order to create faster and more user friendly web pages.
  • (^) It is a client side technology.

Purpose of AJAX

  • (^) Prevents unnecessary reloading of a page.
  • (^) When we submit a form, although most of the page remains the same, whole page is reloaded from the server.
  • (^) This causes very long waiting times and waste of bandwidth.
  • (^) AJAX aims at loading only the necessary innformation, and making only the necessary changes on the current page without reloading the whole page.

Simple Processing

  • (^) AJAX is based on Javascript, and the main functionality is to access the web server inside the Javascript code.
  • (^) We access to the server using special objects; we send data and retrieve data.
  • (^) When user initiates an event, a javascript function is called which accesses server using the objects.
  • (^) The received information is shown to the user by means of the Javascript’s functions.

Example

  • (^) We want to input data into a textbox.
  • (^) We want the textbox to have intellisense property; guess entries according to input.
  • (^) http://www.w3schools.com/ajax/ajax_example.asp
  • (^) Only the ‘span’ part of the html code is changed.

History of AJAX

  • (^) Starts with web pages
  • (^) Static web pages
    • (^) Static html page is loaded
    • (^) No interaction with user
  • (^) Dynamic web pages
    • (^) Html page is generated dynamically
    • (^) Interaction with user
    • (^) Becomes slower as functionality increases
    • (^) Speed becomes untolerable, so AJAX has been born

Alternative Technologies

  • (^) Not a technology, but a combination of technologies.
  • (^) Technologies with similar tasks: URLConnection, ASP and JSP
  • (^) Other technologies returns whole page and client loads it.
  • (^) Only necessary data is returned and that part is updated

C/S Processes

  • (^) Most of the time client requires two files
    • (^) Html page: handles GUI and calls a function of JavaScript.
    • (^) JavaScript: handles the business logic of the system
  • (^) In JavaScript, a request is sent to client and response is taken from server via XMLHTTP object
  • (^) Response of server should be returned in xml file structure
  • (^) Only requested data is returned

Examination of Sample

  • (^) General process will be explained on an example at http://www.w3schools.com/ajax/ajax_database.asp.
  • (^) In this example, one html page and one JavaSocket reside in Client side of the system while an ASP page resides in Server sides.

JavaScript of Example

function showCustomer(str) { var url="getcustomer.asp?sid=" + Math.random() + "&q=" + str xmlHttp=GetXmlHttpObject(stateChanged) xmlHttp.open("GET", url , true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ document.getElementById("txtHint").innerHTML =
xmlHttp.responseText } }

ASP Code of Example

sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID=" sql=sql & request.querystring("q") ............ Open Connection to the DB rs.Open sql, conn response.write("

") do until rs.EOF for each x in rs.Fields response.write("") response.write("") next rs.MoveNext loop response.write("
" & x.name & " & x.value & "
")

Creating the object

  • (^) For IE 5.5: objXmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”)
  • (^) For Mozilla: objXmlHttp=new XMLHttpRequest()

Sending information

  • (^) After creating the object, we can send information to the web server and get the answer using this object’s functions:
  • (^) GET METHOD: xmlhttp.open(“GET”, url, true) xmlhttp.send()
  • (^) POST METHOD: xmlhttp.open("POST", url, true) xmlhttp.send(“date=11-11-2006&name=Ali")
  • (^) Third argument tells that data will be processes asynchronously. When server responds, the “OnReadyStateChange” event handler will be called.

Pros/Cons

  • (^) Advantages:
    • (^) Independent of server technology.
    • (^) Apart from obtaining the XMLHTTP object, all processing is same for all browser types, because Javascript is used.
    • (^) Permits the development of faster and more interactive web applications.
  • (^) Disadvantages:
    • (^) The back button problem. People think that when they press back button, they will return to the last change they made, but in AJAX this doesn not hold.
    • (^) Possible network latency problems. People should be given feedback about the processing.
    • (^) Does not run on all browsers.

Wireless Application Protocol

(WAP)

 (^) Empowers mobile users with wireless devices to easily access and interact with information and services.  (^) A “standard” created by wireless and Internet companies to enable Internet access from a cellular phone  (^) wapforum.org:

  • co-founded by Ericsson, Motorola, Nokia, Phone.com
  • 450 members in 2000, comprise of Handset manufacturers, Wireless service providers, ISPs, Software companies in the wireless industry
  • (^) Goals
    • (^) deliver Internet services to mobile devices
    • enable applications to scale across a variety of transport options and device types
    • (^) independence from wireless network standards
    • (^) GSM, CDMA IS-95, TDMA IS-136, 3G systems (UMTS, W-CDMA)