您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 基于C的ajax功能实现源代码
这是本人在学校时照老师的要求做的最简单的ajax功能,不好勿喷。这代码主要分为html代码和cs后台代码,和数据库连接的功能我就没发数据库了,都是简单的数据库。(基于C#的ajax功能实现代码。),仅供参考。1、地区信息查询htmlxmlns==text/javascriptlanguage=javascriptvarXMLHttpRequest;varrequestType=;functiongetXMLHttpRequest(){if(window.ActiveXObject){XMLHttpRequest=newActiveXObject(Microsoft.XMLHTTP);}elseif(window.XMLHttpRequest){XMLHttpRequest=newXMLHttpRequest();}}functionsendRquest(request){requestType=request;getXMLHttpRequest();XMLHttpRequest.onreadystatechange=stateChange;XMLHttpRequest.open(GET,XMLFile2.xml);XMLHttpRequest.send(null);}functionstateChange(){if(XMLHttpRequest.readyState==4){if(XMLHttpRequest.status==200){if(requestType==north){listNorthStates();}elseif(requestType==all){listAllStates();}elseif(requestType==south){listSouthStates();}elseif(requestType==east){listEastStates();}elseif(requestType==west){listWestStates();}}}}varnorthStates;varsouthStates;vareastStates;varwestStates;varallStates;functionlistNorthStates(){varxmlDOC=XMLHttpRequest.responseXML;varnorthNode=xmlDOC.getElementsByTagName(north)[0];northStates=northNode.getElementsByTagName(state);output(北À¡À部?州Y名?,northStates);}functionlistSouthStates(){varxmlDOC=XMLHttpRequest.responseXML;varsouthNode=xmlDOC.getElementsByTagName(south)[0];southStates=southNode.getElementsByTagName(state);output(南?部?州Y名?,southStates);}functionlistEastStates(){varxmlDOC=XMLHttpRequest.responseXML;vareastStates=xmlDOC.getElementsByTagName(east)[0];eastStates=eastNode.getElementsByTagName(state);output(东?部?州Y名?,eastStates);}functionlistWestStates(){varxmlDOC=XMLHttpRequest.responseXML;varwestStates=xmlDOC.getElementsByTagName(west)[0];westStates=westNode.getElementsByTagName(state);output(西¡Â部?州Y名?,westStates);}functionlistAllStates(){varxmlDOC=XMLHttpRequest.responseXML;allStates=xmlDOC.getElementsByTagName(state);output(所¨´有®D州Y名?,allStates);}functionoutput(title,states){varout=title;varcurrentSate=null;for(vari=0;istates.length;i++){currentState=states[i];out=out+\n-+currentState.childNodes[0].nodeValue;}alert(out);}/script/headbodyh1显?示º?美¨¤国¨²的Ì?州Y名?/h1pinputid=Button1type=buttonvalue=查¨¦看¡ä美¨¤国¨²所¨´有®D州Y名?onclick=sendRquest('all')style=color:#FF0000;background-color:#00FFFF//ppinputid=Button2type=buttonvalue=查¨¦看¡ä美¨¤国¨²北À¡À部?州Y名?onclick=sendRquest('north')style=color:#FF0000;background-color:#00FFFF//pp /pp /pp /p/body/html2、信息增删改查Html页面htmlxmlns==text/javascriptvarxmlHttp;varname;varnum;varBclass;vardeleteID;functioncreateXMLHttpRequest(){if(window.ActiveXObject){xmlHttp=newActiveXObject(Microsoft.XMLHTTP);}elseif(window.XMLHttpRequest){xmlHttp=newXMLHttpRequest();}}functionaddEmployee(){name=document.getElementById(name).value;num=document.getElementById(num).value;Bclass=document.getElementById(Bclass).value;if(name==||num==||Bclass==){return;}varurl=zsgc.aspx?+createAddQueryString(name,num,Bclass,ffstudent);+&ts=+newDate().getTime();createXMLHttpRequest();xmlHttp.onreadystatechange=handleAddStatechange;xmlHttp.open(GET,encodeURI(url),true);xmlHttp.send(null);}functiondelEmployee(){num=document.getElementById(num).value;if(num==){return;}varurl=zsgc.aspx?+createDelQueryString(num,delstuent);+&ts=+newDate().getTime();createXMLHttpRequest();xmlHttp.onreadystatechange=handleAddStatechange;xmlHttp.open(GET,encodeURI(url),true);xmlHttp.send(null);}functioncxEmployee(){num=document.getElementById(num).value;action=cxstudent;if(num==){return;}varurl=zsgc.aspx?+createcxQueryString(num,action);+&ts=+newDate().getTime();createXMLHttpRequest();xmlHttp.onreadystatechange=handleAddStatechange;xmlHttp.open(GET,encodeURI(url),true);xmlHttp.send(null);}functioncreateAddQueryString(name,num,Bclass,action){varqueryString=name=+name+&num=+num+&Bclass=+Bclass+&action=+action;returnqueryString;}functioncreateDelQueryString(num,action){varqueryString=num=+num+&action=+action;returnqueryString;}functioncreatecxQueryString(num,action){varqueryString=num=+num+&action=+action;returnqueryString;}functionhandleAddStatechange(){if(xmlHttp.readyState==4){if(xmlHttp.status==200){alert(xmlHttp.responseText);clearInputBoxes();}else{alert(Errorwhileaddingemployee.);}}}functionclearInputBoxes(){document.getElementById(name).value=;document.getElementById(num).value=;document.getElementById(Bclass).value=;}/script/headbodybackground=img/3.jpgh1 学¡ì生¦¨²信?息¡é/h1tabletrtd姓?名?:êo/tdtdinputid=nametype=text//tdtd学¡ì号?:êo/tdtdinputid=numtype=text//tdtd班㨤级?:êo/tdtdinputid=Bclasstype=text//td/trtrtdcolspan=2align=centerinputid=Button1type=buttonvalue=添¬¨ª加¨®onclick=addEmployee();//tdtdcolspan=2align=centerinputid=Button2type=buttonvalue=删¦?除yonclick=delEmployee();//tdtdcolspan=2align=centerinputid=Button3type=buttonvalue=查¨¦询¡¥onclick=cxEmployee();//td/tr/table/body/htmlCs后台代码.usingSyste
本文标题:基于C的ajax功能实现源代码
链接地址:https://www.777doc.com/doc-2569018 .html