/Users/andrea/_magisterarbeit/korpus/clean/trainkorpus/32/file7.html NN ----------------------------------------- : Level NP . SENT IntermediatePhilip NP McCarthy NP philmccarthy JJ gmail NN . SENT com NN , , Software NP Development NP Consultant NN , , Independent JJ Consultant NN 20 CD Sep NN 2005 CD Listing NN 1 CD . SENT Relevant JJ fragments NNS of IN the DT shopping NN cart NN example NN . SENT Table NN of IN products NNS from IN store's JJ catalog NN , , one CD row NN per IN item NN th NN Name NN th NN th NN Description NN th NN th NN Price NP th NN th NN th NN . SENT . SENT . SENT tr NP . SENT Item NN details NNS td NP Hat NN td NP td NP Stylish JJ bowler NN hat NN td NP td NP 19 CD . SENT 99 CD td NP td NP . SENT Click NN button NN to TO add VV item NN to TO cart NN via IN Ajax NP request NN button NN onclick NN addToCart NN hat NN 001 RB Add VV to TO Cart NP button NN td NP tr NP . SENT . SENT . SENT . SENT Representation NN of IN shopping NN cart NN , , updated VVN asynchronously RB ul JJR id NN cart NN contents NNS . SENT List NN items NNS will MD be VB added VVN here RB for IN each DT item NN in IN the DT cart NN ul NN . SENT Total JJ cost NN of IN items NNS in IN cart NN displayed VVN inside IN span NN element NN Total JJ cost NN . SENT span NN id NN total JJ 0 CD . SENT 00 CD span NN Back RB to TO topDispatching VVG an DT XMLHttpRequest JJS Listing VVG 2 CD . SENT Creating VVG a DT cross NN browser NN XMLHttpRequest JJS Returns NNS a DT new JJ XMLHttpRequest JJS object NN , , or CC false JJ if IN this DT browser NN doesn't NN support NN it PP function VVP newXMLHttpRequest JJS var NN xmlreq NNS false JJ . SENT if IN window NN . SENT XMLHttpRequest JJS Create VVP XMLHttpRequest JJS object NN in IN non JJ Microsoft NP browsers NNS xmlreq VVD new JJ XMLHttpRequest NP . SENT else RB if IN window NN . SENT ActiveXObject NN Create VVP XMLHttpRequest JJS via IN MS NN ActiveX NP try VVP Try VV to TO create VV XMLHttpRequest JJS in IN later JJR versions NNS of IN Internet NN Explorer NN xmlreq JJ new JJ ActiveXObject NN Msxml NP 2 CD . SENT XMLHTTP NP . SENT catch NN e SYM 1 CD Failed JJ to TO create VV required JJ ActiveXObject NN try VVP Try VV version NN supported VVN by IN older JJR versions NNS of IN Internet NN Explorer NN xmlreq NP new JJ ActiveXObject NP Microsoft NP . SENT XMLHTTP NP . SENT catch NN e SYM 2 CD Unable JJ to TO create VV an DT XMLHttpRequest JJS with IN ActiveX NP return NN xmlreq NP . SENT Listing NN 3 CD puts VVZ these DT steps NNS together RB . SENT Listing VVG 3 CD . SENT Dispatching VVG an DT Add VV to TO Cart NP XMLHttpRequest NP Adds VVZ an DT item NN , , identified VVN by IN its PP$ product NN code NN , , to TO the DT shopping NN cart NN itemCode NN product NN code NN of IN the DT item NN to TO add VV . SENT function NN addToCart NN itemCode NN Obtain VV an DT XMLHttpRequest JJS instance NN var NN req JJ newXMLHttpRequest NN . SENT Set VV the DT handler NN function NN to TO receive VV callback NN notifications NNS from IN the DT request NN object NN var NN handlerFunction NN getReadyStateHandler NN req NP , , updateCart NN . SENT req NP . SENT onreadystatechange NN handlerFunction NN . SENT Open VV an DT HTTP NP POST NN connection NN to TO the DT shopping NN cart NN servlet NN . SENT Third JJ parameter NN specifies VVZ request NN is VBZ asynchronous JJ . SENT req NP . SENT open JJ POST NN , , cart NN . SENT do VV , , true JJ . SENT Specify VV that IN the DT body NN of IN the DT request NN contains VVZ form NN data NNS req JJ . SENT setRequestHeader JJR Content NN Type NN , , application NN x SYM www JJ form NN urlencoded NN . SENT Send VV form VV encoded VVN data NNS stating VVG that IN I PP want VVP to TO add VV the DT specified JJ item NN to TO the DT cart NN . SENT req NP . SENT send VV action NN add VV item NN itemCode NN . SENT Back RB to TO topServlet NN request NN handling NN Listing VVG 4 CD . SENT Servlet NN code NN to TO handle VV Ajax NP requests NNS public JJ void NN doPost NN HttpServletRequest NP req NP , , HttpServletResponse NP res NN throws VVZ java NP . SENT io NP . SENT IOException NP Cart NP cart NN getCartFromSession NN req NP . SENT String NN action NN req NP . SENT getParameter NN action NN . SENT String NN item NN req NP . SENT getParameter NN item NN . SENT if IN action NN . SENT null JJ item NN . SENT null NN Add VV or CC remove VV items NNS from IN the DT Cart NP if IN add VV . SENT equals VVZ action NN cart NN . SENT addItem NN item NN . SENT else RB if IN remove VV . SENT equals VVZ action NN cart NN . SENT removeItems NNS item NN . SENT Serialize VV the DT Cart's NP state NN to TO XML NP String NP cartXml NN cart NN . SENT toXml NN . SENT Write VV XML NP to TO response NN . SENT res NNS . SENT setContentType NN application NN xml NN . SENT res NNS . SENT getWriter JJR . SENT write VV cartXml NN . SENT Listing NN 5 CD shows NNS an DT example NN of IN the DT XML NP produced VVD by IN the DT Cart NP . SENT toXml NN method NN . SENT It's NP pretty RB straightforward JJ . SENT Note VV the DT generated VVN attribute NN on IN the DT cart NN element NN , , which WDT is VBZ a DT timestamp NN produced VVN by IN System NP . SENT currentTimeMillis NNS . SENT Listing VVG 5 CD . SENT Example NN XML NN serialization NN of IN the DT Cart NP object NN . SENT xml NN version NN 1 CD . SENT 0 CD . SENT cart NN generated VVD 1123969988414 CD total NN 171 CD . SENT 95 CD item NN code NN hat NN 001 CD name NN Hat NN name NN quantity NN 2 CD quantity NN item NN item NN code NN cha NP 001 CD name NN Chair NN name NN quantity NN 1 CD quantity NN item NN item NN code NN dog NN 001 CD name NN Dog NP name NN quantity NN 1 CD quantity NN item NN cart NN Back RB to TO topResponse NN handling NN with IN JavaScript NN Listing VVG 6 CD . SENT The DT getReadyStateHandler NN function NN Returns VVZ a DT function NN that WDT waits VVZ for IN the DT specified JJ XMLHttpRequest JJS to TO complete VV , , then RB passes VVZ its PP$ XML NP response NN to TO the DT given VVN handler NN function NN . SENT req NP The NP XMLHttpRequest NP whose WP$ state NN is VBZ changing VVG responseXmlHandler JJR Function NN to TO pass VV the DT XML NP response NN to TO function VV getReadyStateHandler NP req NP , , responseXmlHandler NN Return NN an DT anonymous JJ function NN that WDT listens VVZ to TO the DT XMLHttpRequest JJS instance NN return NN function NN If IN the DT request's JJ status NN is VBZ complete JJ if IN req NP . SENT readyState NN 4 CD Check NP that IN a DT successful JJ server NN response NN was VBD received VVN if IN req NP . SENT status NN 200 CD Pass NP the DT XML NP payload NN of IN the DT response NN to TO the DT handler NN function NN responseXmlHandler NN req NP . SENT responseXML NN . SENT else RB An DT HTTP NP problem NN has VHZ occurred VVN alert JJ HTTP NP error NN . SENT req NP . SENT status NN . SENT Listing VVG 7 CD . SENT Updating VVG the DT page NN to TO reflect VV the DT cart NN XML NN document NN function NN updateCart NN cartXML NN Get VV the DT root NN cart NN element NN from IN the DT document NN var NN cart NN cartXML NN . SENT getElementsByTagName JJ cart NN 0 CD . SENT Check NN that IN a DT more RBR recent JJ cart NN document NN hasn't NN been VBN processed VVN already RB var NN generated VVD cart NN . SENT getAttribute NN generated VVD . SENT if IN generated VVN lastCartUpdate JJ lastCartUpdate NN generated VVD . SENT Clear JJ the DT HTML NP list NN used VVD to TO display VV the DT cart NN contents NNS var NN contents NNS document NN . SENT getElementById JJ cart NN contents NNS . SENT contents NNS . SENT innerHTML NN . SENT Loop NN over IN the DT items NNS in IN the DT cart NN var NN items NNS cart VVP . SENT getElementsByTagName JJ item NN . SENT for IN var NN I NP 0 CD . SENT I PP items NNS . SENT length NN . SENT I PP var NN item NN items NNS I PP . SENT Extract VV the DT text NN nodes NNS from IN the DT name NN and CC quantity NN elements NNS var NN name NN item NN . SENT getElementsByTagName JJ name NN 0 CD . SENT firstChild NN . SENT nodeValue NN . SENT var NN quantity NN item NN . SENT getElementsByTagName JJ quantity NN 0 CD . SENT firstChild NN . SENT nodeValue NN . SENT Create VV and CC add VV a DT list NN item NN HTML NP element NN for IN this DT cart NN item NN var NN li NP document NN . SENT createElement NP li NP . SENT li NP . SENT appendChild NN document NN . SENT createTextNode NN name NN x SYM quantity NN . SENT contents NNS . SENT appendChild NP li NP . SENT Update VV the DT cart's NNS total VVP using VVG the DT value NN from IN the DT cart NN document NN document NN . SENT getElementById JJ total NN . SENT innerHTML NN cart NN . SENT getAttribute JJ total NN . SENT