AJAX - GET Request - GET Request

Ajax GET Request

X in XML
1. The X in AJAX comes from XML
2. In an XML HTTP request, we usually expect the

server to respond with some XML

3. What is XML?

A specification for creating languages to store data; used to share data between systems a basic syntax of tags & attributes languages written in XML specify tag names, attribute names, and rules of use Example: XHTML is a "flavor" of XML

4. Short answer: like HTML but You can make up your own tag names
All tags have to be closed (and there is a shorthand)
Uses of XML
  • XML data comes from many sources on the web
  • web servers store data as XML files
  • databases sometimes return query results as XML
  • Web services use XML to communicate
  • XML languages are used for music, math, vector graphics
  • XML file

    the new tags (we just made them up)

    An XML version number

    One tag contains everything (and becomes the root of the document tree)

    <?xml version="1. 0" encoding="ISO-8859-1"?>
    <body>Largest collection of programs</body>
    XML Responding
    1. We can look at the XML text within a response using the responseText property.
    2. Even better, we can use the responseXML property to access the XML.
    3. Best, responseXML. documentElement contains the document tree for the XML.
    4. This is a document tree in the DOM model that we've seen before (just like document).
    function sendRequest() {
    var xmlHttp = GetXmlHttpObject();
    if (! xmlHttp) {
    return false;
    mlHttp. onreadystatechange = function() {
    if (xmlHttp. readyState == 4) {
    var xmlDoc =
    xmlHttp. responseXML. documentElement;
    ar requestURI = xmlURI;
    xmlHttp. open("GET", requestURI, true);
    xmlHttp. send(null);
    Prototype Ajax methods and properties

    That can be passed to the Ajax.Request constructor:

    method : how to fetch the request from the server (default "post" )
    parameters : query parameters to pass to the server, if any asynchronous (default true), contentType, encoding, requestHeaders events in the Ajax.Request object that you can handle:
    onSuccess : request completed successfully
    onFailure : request was unsuccessful
    onCreate, onComplete, onException, on### (handler for HTTP error code ###)
    Ajax testing on browser
  • If you field an internal application, test on all officially sanctioned browsers on all supported operating systems.
  • If you field an external application, test on as many browsers as possible. Preferably: IE 6, IE 7, IE 8, a recent Firefox implementation, and Chrome. Safari and Opera can’t hurt, but are less used less used.
  • Test regularly on IE and Firefox. Test on Chrome and a wider set of browsers before deploying.
  • Browser market share:
  • Access stats on (August 2010) – IE: 42.4%, Firefox: 41.1%, Chrome: 12.8%, Safari: 1.4%, Opera: 1.3%