基于C#的ajax 功能实现 源代码.docx
《基于C#的ajax 功能实现 源代码.docx》由会员分享,可在线阅读,更多相关《基于C#的ajax 功能实现 源代码.docx(42页珍藏版)》请在冰点文库上搜索。
基于C#的ajax功能实现源代码
这是本人在学校时照老师的要求做的最简单的ajax功能,不好勿喷。
这代码主要分为html代码和cs后台代码,和数据库连接的功能我就没发数据库了,都是简单的数据库。
(基于C#的ajax功能实现代码。
),仅供参考。
1、地区信息查询
//www.w3.org/1999/xhtml">
varXMLHttpRequest;
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;icurrentState=states[i];
out=out+"\n-"+currentState.childNodes[0].nodeValue;}
alert(out);}
<
/head>
<
h1>显?
示º?
美¨¤国¨²的Ì?
州Y名?
"onclick="sendRquest('all')"
style="color:
#FF0000;background-color:
#00FFFF"/>
州Y名?
"
onclick="sendRquest('north')"
style="color:
#FF0000;background-color:
#00FFFF"/>
2、信息增删改查
Html页面
//www.w3.org/1999/xhtml">
varxmlHttp;
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="";}
学¡ì生¦¨²信?
息¡é
姓? 名? : êo |
| 学¡ì号? : êo |
| 班㨤级? : êo |
|
除y"onclick="delEmployee();"/>
|