欢迎来到天天文库
浏览记录
ID:28025139
大小:115.50 KB
页数:15页
时间:2018-12-07
《基于web页面的客服系统中英文》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、外文翻译院系北方软件学院专业计算机科学与技术班级5233108学号200502331254姓名孙勤指导教师韩宇负责教师韩宇沈阳航空工业学院2007年6月MakeasynchronousrequestswithJavaScriptandAjaxMostWebapplicationsusearequest/responsemodelthatgetsanentireHTMLpagefromtheserver.Theresultisaback-and-forththatusuallyinvolvesclickingabutton,waitingfortheserver,clicking
2、anotherbutton,andthenwaitingsomemore.WithAjaxandtheXMLHttpRequestobject,youcanusearcqucst/rcsponscmodelthatneverleavesuserswaitingforaservertorespond.InthisintroducedaboutallAjax-relatedobjectsandprogrammingapproaches:TheXMLHttpRequestobject.ThisobjectisreallytheonlycommonthreadacrossallAjax
3、applications.IntroducingXMLHttpRequestAJavaScriptobjectcalledXMLHttpRequest.whichhasactuallybeenaroundinseveralbrowsersforquiteawhile,thesearejustafewofthemethodsandpropertiesyou’lluseonthisobject:•open():Setsupanewrequesttoaserver.•scnd():Sendsarequesttoaserver.•abort():Bailsoutofthecurrent
4、request.•readyState:ProvidesthecurrentHTMLreadystate.•responseText:Thetextthattheserversendsbacktorespondtoarequest.ThesimplicityofnewFirst,youneedtocreateanewvariableandassignittoaninstanceoftheXMLHttpRequestobject.That’sprettysimpleinJavaScript;youjustusethenewkeywordwiththeobjectname。Soyo
5、ucreateavariableinJavaScriptwithvar,giveitaname(like"request"),andthenassignittoanewinstanceofXMLHttpRequest.Atthatpoint,you’rereadytousetheobjectinyourfunctions.ErrorhandlingInreallife,thingscangowrongandthiscodedoesn’tprovideanyerror-handling.Aslightlybetterapproachistocreatethisobjectandh
6、aveitfailifsomethinggoeswrong.Createanewvariablecalledrequestandassignitafalsevalue.You’11usefalseasaconditionthatmeanstheXMLHttpRequestobjecthasn’tbeencreatedyet.Addinatry/catchblock:1TryandcreatetheXMLHttpRequestobject.2.2Ifthatfails(catch(failed)),ensurethatrequestisstillsettofalse.Checka
7、ndseeifrequestisstillfalse(ifthingsaregoingokay,itwon’tbe).Iftherewasaproblem(andrequestisfalse),useaJavaScriptalerttotelluserstherewasaproblem.Nowyou’vegotanerror-proofpieceofcodethatcreatesanXMLHttpRequestobjectandevenletsyouknowifsomethingwentwr
此文档下载收益归作者所有