ajax英文文献Word文档下载推荐.doc

上传人:b****1 文档编号:13159947 上传时间:2022-10-07 格式:DOC 页数:9 大小:137KB
下载 相关 举报
ajax英文文献Word文档下载推荐.doc_第1页
第1页 / 共9页
ajax英文文献Word文档下载推荐.doc_第2页
第2页 / 共9页
ajax英文文献Word文档下载推荐.doc_第3页
第3页 / 共9页
ajax英文文献Word文档下载推荐.doc_第4页
第4页 / 共9页
ajax英文文献Word文档下载推荐.doc_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

ajax英文文献Word文档下载推荐.doc

《ajax英文文献Word文档下载推荐.doc》由会员分享,可在线阅读,更多相关《ajax英文文献Word文档下载推荐.doc(9页珍藏版)》请在冰豆网上搜索。

ajax英文文献Word文档下载推荐.doc

XMLHttpRequest;

WebApplications

I.INTRODUCTION

AjaxisshorthandforAsynchronousJavaScriptandXML(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’soriginaluseas

ahypertextmedium,butasfansoftheElementsofUserExperienceknow,whatmakestheWebgoodforhypertextdoesn’tnecessarilymakeitgoodforsoftwareapplications.

Thisapproachmakesalotoftechnicalsense,butitdoesn’tmakeforagreatuserexperience.Whiletheserverisdoingitsthing,what’stheuserdoing?

That’sright,waiting.Andateverystepinatask,theuserwaitssomemore.Obviously,wewouldn’tmakeuserswaitaroundindesigningtheWebfromscratchforapplications.Onceaninterfaceisloaded,whyshouldtheuserinteractioncometoahalteverytimetheapplicationneedssomethingfromtheserver?

Infact,whyshouldtheuserseetheapplicationgototheserveratall?

II.MAKEASYNCHRONOUSREQUESTSWITH

JAVASCRIPTANDAJAX

MostWebapplicationsusearequest/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.CreateanewXMLHttpRequestobject

Inreallife,thingscangowrongandthiscodedoesn'

tprovideanyerror-handling.Aslightlybetterapproachistocreatethisobjectandhaveitgracefullyfailifsomethinggoeswrong.Forexample,manyolderbrowsers(believeitornot,peoplearestillusingoldversionsofNetscapeNavigator)don'

tsupportXMLHttpRequestandWebapplicationsneedtoletthoseusersknowthatsomethinghasgonewrong.Fig.3showshowtocreatethisobjectsoifsomethingfails,itthrowsoutaJavaScriptalert.

Figure3.CreateXMLHttpRequestwithsomeerror-handlingabilities

ItturnsoutthatMicrosoftsupportsAjax,butcallsitsversionofXMLHttpRequestsomethingdi

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > IT认证

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1