您好,欢迎访问三七文档
ResearchonWebApplicationsUsingAjaxNewTechnologiesAbstract—Ajaxisreallyseveraltechnologies,eachflourishinginitsownright,comingtogetherinpowerfulnewways,whichconsistsofHTML,JavaScript.technology,DHTML,andDOM,isanoutstandingapproachthathelpstotransformclunkyWebinterfacesintointeractiveAjaxapplications.AfterthedefinitiontoAjax,howtomakeasynchronousrequestswithJavaScriptandAjaxwasintroduced.Attheend,advancedrequestsandresponsesinAjaxwereputforward.Keywords-component;Ajax;JavaScript;XMLHttpRequest;WebApplicationsI.INTRODUCTIONAjaxisshorthandforAsynchronousJavaScriptandXML(andDHTML,andsoon).ThephrasewascoinedbyJesseJamesGarrettofAdaptivePathandis,accordingtoJesse,notmeanttobeanacronym.However,Ajaxisfarmorethanjustafad;it'sapowerfulapproachtobuildingWebsitesandit'snotnearlyashardtolearnasanentirenewlanguage.Figure1.Thetraditionalmodelforwebapplications(left)comparedtotheAjaxmodel(right)Ajaxisn’tatechnology.It’sreallyseveraltechnologies,eachflourishinginitsownright,comingtogetherinpowerfulnewways.Ajaxincorporates:.standards-basedpresentationusingXHTMLandCSS;.dynamicdisplayandinteractionusingtheDocumentObjectModel;.datainterchangeandmanipulationusingXMLandXSLT;.asynchronousdataretrievalusingXMLHttpRequest;.JavaScriptbindingeverythingtogether.Theclassicwebapplicationmodelworkslikethis:MostuseractionsintheinterfacetriggeranHTTPrequestbacktoawebserver.Theserverdoessomeprocessing—retrievingdata,crunchingnumbers,talkingtovariouslegacysystems—andthenreturnsanHTMLpagetotheclient.It’samodeladaptedfromtheWeb’soriginaluseasahypertextmedium,butasfansoftheElementsofUserExperienceknow,whatmakestheWebgoodforhypertextdoesn’tnecessarilymakeitgoodforsoftwareapplications.Thisapproachmakesalotoftechnicalsense,butitdoesn’tmakeforagreatuserexperience.Whiletheserverisdoingitsthing,what’stheuserdoing?That’sright,waiting.Andateverystepinatask,theuserwaitssomemore.Obviously,wewouldn’tmakeuserswaitaroundindesigningtheWebfromscratchforapplications.Onceaninterfaceisloaded,whyshouldtheuserinteractioncometoahalteverytimetheapplicationneedssomethingfromtheserver?Infact,whyshouldtheuserseetheapplicationgototheserveratall?II.MAKEASYNCHRONOUSREQUESTSWITHJAVASCRIPTANDAJAXMostWebapplicationsusearequest/responsemodelthatgetsanentireHTMLpagefromtheserver.Theresultisaback-and-forththatusuallyinvolvesclickingabutton,waitingfortheserver,clickinganotherbutton,andthenwaitingsomemore.WithAjaxandtheXMLHttpRequestobject,wecanusearequest/responsemodelthatneverleavesuserswaitingforaservertorespond.A.IntroducingXMLHttpRequestXMLHttpRequesthasactuallybeenaroundinseveralbrowsersforquiteawhile,whichisthekeytoWeb2.0,Ajax,andprettymucheverything.Togiveareallyquickoverview,thesearejustafewofthemethodsandpropertieswillbeusedonthisobject:.open():Setsupanewrequesttoaserver..send():Sendsarequesttoaserver..abort():Bailsoutofthecurrentrequest..readyState:ProvidesthecurrentHTMLreadystate..responseText:Thetextthattheserversendsbacktorespondtoarequest.Eachofthesemethodsandpropertiesrelatetosendingarequestanddealingwitharesponse.Infact,ifwesaweverymethodandpropertyofXMLHttpRequest,theywouldallrelatetothatverysimplerequest/responsemodel.Soclearly,wewon'tlearnaboutanamazingnewGUIobjectorsomesortofsuper-secretapproachtocreatinguserinteraction;programmerswillworkwithsimplerequestsandsimpleresponses.Itmightnotsoundexciting,butcarefuluseofthisoneobjectcantotallychangeourapplications.First,weneedtocreateanewvariableandassignittoaninstanceoftheXMLHttpRequestobject.That'sprettysimpleinJavaScript,justusethenewkeywordwiththeobjectname,likeinFig.2.Figure2.CreateanewXMLHttpRequestobjectInreallife,thingscangowrongandthiscodedoesn'tprovideanyerror-handling.Aslightlybetterapproachistocreatethisobjectandhaveitgracefullyfailifsomethinggoeswrong.Forexample,manyolderbrowsers(believeitornot,peoplearestillusingoldversionsofNetscapeNavigator)don'tsupportXMLHttpRequestandWebapplicationsneedtoletthoseusersknowthatsomethinghasgonewrong.Fig.3showshowtocreatethisobjectsoifsomethingfails,itthrowsoutaJavaScriptalert.Figure3.CreateXMLHttpRequestwithsomeerror-handlingabilitiesItturnsoutthatMicrosoftsupportsAjax,butcallsitsversionofXMLHttpRequestsomethingdifferent.Infact,itcallsitseveraldifferentthings.WhenusinganewerversionofInternetExplorer,programmersneedtouseanobjectcalledMsxml2.XMLHTTP.SomeolderversionsofInternetExploreruseMicrosoft.XMLHTTPtosupportthesetwoobjecttypes(withoutlosingthesupportalreadyhavefornon-Microsoftbrowsers).CheckoutFig.4whichaddsMicrosoftsupporttothecodewe'vealreadyseen.Infact,Microsoft'snewestversionofInternetExplorer—version7.0,settocomeoutlatein2006--issupposedtomovetosupportingXMLHttpRequestdirectly,allowingprogrammerstousethenewkeywordinsteadofalltheMsxml2.XMLHTTPcreationcode.Figure4.AddsupportforMicrosoftbrowsersB.SendingrequestswithXMLHttpRequestXMLHttpRequest'sonlypurposeistoallowdeveloperstomakerequestsandreceiveresponses.Everythingelseischangingtheuserinterface,swappingoutimages,eveninterpretingthedatathattheserversendsback—isthejobofJavaScript,CSS,orothercodeinWebpages.WithXMLH
本文标题:ajax英文文献
链接地址:https://www.777doc.com/doc-5341483 .html