HowTo Ajax Aug2011

download HowTo Ajax Aug2011

of 6

Transcript of HowTo Ajax Aug2011

  • 8/12/2019 HowTo Ajax Aug2011

    1/6

    www.uttarainfo.com

    Ajax How To

    Preface

    The purpose of this document is to assist in integrating AJAX functionality into an application.

    Introduction

    AJAX is an acronym for - Asynchronous JavaScript and XML.

    It is used for exchanging data asynchronously between browser and server to avoid full page

    reloads (behind the scenes and in parallel).

    Technical details

    AJAX request-response cycle consists of the following phases called readyState!s". They are -

    o # $ %&S'&T $ The o()ect has (een constructed

    o * $ +,'&' $ Server connection esta(lished

    o $ /'A'0S10'2'34' $5inal request headers received 6including redirects7

    o 8 $ L+A3&9 $ The response entity (ody is (eing received.

    o : $+&' $ The data transfer has (een completed or something went wrong during the

    transfer

    The possi(le /TT, request status codes are $

    o *;; - 3nformational

    o ;; - Successful

    o 8;; - 0edirection

    o :;; - 2lient 'rror

    http://www.uttarainfo.com/http://www.uttarainfo.com/
  • 8/12/2019 HowTo Ajax Aug2011

    2/6

    o

  • 8/12/2019 HowTo Ajax Aug2011

    3/6

    ajax-request.html

    BE+2TF,'html,%GL32H-I82T /TML :.#* Transitional'&[email protected]:loose.dtdHC

    BhtmlC

    BheadC

    Bmetahttp-equiv"Content-Type"content"text/html; charset=ISO-885-!"C

    BtitleCA)a; - /owTo - 0equestBtitleC

    Bscripttype"text/a#ascr$pt"src"aax-scr$pt%s"CBscriptC

    Bscripttype"text/a#ascr$pt"C

    functionsend0equest67 K

    %0Ls that (egin with http 6protocol7 are a(solute %0Ls

    and need to (e specified in full.

    5or e;ample @ http@localhost@D#D#a)a;a)a;-response.t;t

    %0Ls that (egin with are relative to the

    server-root-address and are appended to it.

    5or e;ample @ http@localhost@D#D# is prefi;ed to a)a;a)a;-response.t;t

    +ther %0Ls are )ust appended to the last with respect to the %0L of page

    5or e;ample @ http@localhost@D#D#a)a; is prefi;ed to a)a;-response.t;t

    handleA)a;0equest6Ha)a;-response.t;tH? a)a;2allGac=/andler7N

    O

  • 8/12/2019 HowTo Ajax Aug2011

    4/6

    ajax-request.html Continued

    This function will (e passed as the call(ac= function.

    3n this case? the call(ac= is invo=ed each time the ready state changes.

    functiona)a;2allGac=/andler6;ml/ttp0eq+()7 K

    document.get'lementGy3d6Ha)a;0esponse2ontainerH7.inner/TML ;ml/ttp0eq+().readyStateN

    'ven though this function is called on each and every change to the

    ready state? this function only handles the com(ination of the following -

    request sent and response received 6readyState-:7 and the result of the request

    (eing successful 6Status-##7

    Gesides the H##-+PH status? the other common http-request states include

    H:#:-&ot foundH and H

  • 8/12/2019 HowTo Ajax Aug2011

    5/6

    ajax-response.txt

    ajax-script.js

    BiC/elloIorldBiC

    functiono(tainA)a;0eq+()67 K

    var;ml/ttp0eq+()N

    tryK

    if6window.XML/ttp0equest7

    K

    code for 3'QR? 5irefo;? 2hrome? +pera? Safari

    ;ml/ttp0eq+()newXML/ttp0equest67N

    O

    else

    K

    code for 3'? 3'