基于C#的ajax 功能实现 源代码.docx

上传人:b****8 文档编号:9922277 上传时间:2023-05-22 格式:DOCX 页数:42 大小:31.37KB
下载 相关 举报
基于C#的ajax 功能实现 源代码.docx_第1页
第1页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第2页
第2页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第3页
第3页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第4页
第4页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第5页
第5页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第6页
第6页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第7页
第7页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第8页
第8页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第9页
第9页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第10页
第10页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第11页
第11页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第12页
第12页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第13页
第13页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第14页
第14页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第15页
第15页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第16页
第16页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第17页
第17页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第18页
第18页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第19页
第19页 / 共42页
基于C#的ajax 功能实现 源代码.docx_第20页
第20页 / 共42页
亲,该文档总共42页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

基于C#的ajax 功能实现 源代码.docx

《基于C#的ajax 功能实现 源代码.docx》由会员分享,可在线阅读,更多相关《基于C#的ajax 功能实现 源代码.docx(42页珍藏版)》请在冰点文库上搜索。

基于C#的ajax 功能实现 源代码.docx

基于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;i

currentState=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="";}

         学¡ì生¦¨²信?

息¡é

除y"onclick="delEmployee();"/>

姓?

名?

êo

学¡ì号?

êo

班㨤级?

êo

Cs后台代码.

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Data;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Data.SqlClient;

publicpartialclasszsgc:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

stringstr="DataSource=.;InitialCatalog=Student;IntegratedSecurity=True";

SqlConnectioncoon=newSqlConnection(str);

SqlCommandcmd=newSqlCommand();

try{

coon.Open();

stringaction=Request["action"].ToString();

stringnum=Request["num"].ToString();

if(action=="ffstudent")

{stringBclass=Request["Bclass"].ToString();

stringname=Request["name"].ToString();

SqlParameter[]par={

newSqlParameter("@name",name),

newSqlParameter("@num",num),

newSqlParameter("@Bclass",Bclass)};

cmd.Connection=coon;

cmd.CommandText="ffstudent";

cmd.CommandType=CommandType.StoredProcedure;

cmd.Parameters.AddRange(par);

inti=cmd.ExecuteNonQuery();

if(i>0){

Response.Write("添¬¨ª加¨®成¨¦功|!

ê?

");}

else{

Response.Write("添¬¨ª加¨®失º¡ì败㨹!

ê?

");}}

elseif(action=="delstuent"){

SqlParameter[]par={

newSqlParameter("@num",num)};

cmd.Connection=coon;

cmd.CommandText="delstuent";

cmd.CommandType=CommandType.StoredProcedure;

cmd.Parameters.AddRange(par);

inti=cmd.ExecuteNonQuery();

if(i>0){

Response.Write("删¦?

除y成¨¦功|!

ê?

");}

else{

Response.Write("删¦?

除y失º¡ì败㨹!

ê?

");}}

elseif(action=="cxstudent"){

DataTabledt=newDataTable();

SqlParameter[]par={

newSqlParameter("@num",num)};

cmd.Connection=coon;

cmd.CommandText="cxstudent";

cmd.CommandType=CommandType.StoredProcedure;

cmd.Parameters.AddRange(par);

SqlDataAdapterda=newSqlDataAdapter(cmd);

da.Fill(dt);

stringstr1="";

for(inti=0;i

str1+=dt.Rows[i][0].ToString()+":

"+dt.Rows[i][1].ToString()+":

"+dt.Rows[i][2].ToString();}

Response.Write(str1);}

coon.Close();}

catch(Exceptione1)

{

Response.Write(e1.ToString());}}}

3、注册

//www.w3.org/1999/xhtml">

无T标À¨º题¬a页°3

varxmlHttp;

functionvilidation(){

xmlHttp=newActiveXObject("Microsoft.XMLHTTP");

varname=document.getElementById("Txt1");

if(name.value!

=""){

xmlHttp.open("Post","zhuce.aspx?

name="+name.value);

xmlHttp.onreadystatechange=OnMessageBack;

xmlHttp.send(null);}

else{alert("用®?

户¡ì名?

不?

能¨¹为a空?

ê?

");}}

functionOnMessageBack(){

if(xmlHttp.readystate==4&&xmlHttp.status==200){

alert(document.write(xmlHttp.responsetext));}}

#00FF00">

用®?

户¡ì注Á¡é册¨¢验¨¦证¡è

value="注Á¡é册¨¢"onclick="vilidation();"/>

<

/body>

Cs

usingSystem;

usingSystem.Collections;

usingSystem.Configuration;

usingSystem.Data;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.HtmlControls;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Xml.Linq;

usingSystem.Data.SqlClient;

publicpartialclasszhuce:

System.Web.UI.Page{

protectedvoidPage_Load(objectsender,EventArgse){

if(Request["name"]!

=""){

stringname=this.Request["name"];

stringconnStr="DataSource=.;InitialCatalog=User;IntegratedSecurity=True;Pooling=False";

SqlConnectionconn=newSqlConnection(connStr);

conn.Open();

stringselStr="select*fromdbo.use1wherename='"+name+"'";

SqlCommandcom=newSqlCommand(selStr,conn);

SqlDataReaderda=com.ExecuteReader();

if(da.Read()){

Response.Write("用®?

户¡ì名?

已°?

存ä?

在¨²!

ê?

ê?

");}else{

Response.Write("注Á¡é册¨¢成¨¦功|!

ê?

ê?

");}}}

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

当前位置:首页 > 经管营销 > 公共行政管理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2