1、ajax方面(东西比较杂,很多相关于.net挂钩的服务器端接触没有实际操作,全部放进来,或许以后当作demo使用)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>$.get发送请求</title> | |
<script type="text/javascript" | |
src="Jscript/jquery-1.4.2-vsdoc.js"> | |
</script> | |
<script type="text/javascript" | |
src="Jscript/jquery-1.4.2.js"> | |
</script> | |
<style type="text/css"> | |
body{font-size:13px} | |
.divFrame{width:260px;border:solid 1px #666} | |
.divFrame .divTitle{padding:5px;height:23px} | |
.divFrame .divTitle span{float:left;padding:2px} | |
.divFrame .divContent{padding:8px} | |
.divFrame .divContent .clsShow{font-size:14px} | |
.txt{border:#666 1px solid;padding:2px;width:118px;float:left;margin-right:3px} | |
.btn {border:#666 1px solid;padding:2px;width:80px;float:left; | |
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff, EndColorStr=#ECE9D8);} | |
</style> | |
<script type="text/javascript"> | |
$(function() { | |
$("#Button1").click(function() { //按钮单击事件 | |
//打开文件,并通过回调函数返回服务器响应后的数据 | |
$.get("UserInfo.aspx", | |
{ name: encodeURI($("#txtName").val()) }, | |
function(data) { | |
$("#divTip") | |
.empty() //先清空标记中的内容 | |
.html(data); //显示服务器返回的数据 | |
}) | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
<div class="divFrame"> | |
<div class="divTitle"> | |
<span>姓名:</span> | |
<input id="txtName" type="text" class="txt" /> | |
<input id="Button1" type="button" | |
class="btn" value="请求数据" /> | |
</div> | |
<div class="divContent"> | |
<div id="divTip"></div> | |
</div> | |
</div> | |
</body> | |
</html> | |
//下面是对应的userinfo.aspx的页面 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>serialize()序列化表单</title> | |
<script type="text/javascript" | |
src="Jscript/jquery-1.4.2-vsdoc.js"> | |
</script> | |
<script type="text/javascript" | |
src="Jscript/jquery-1.4.2.js"> | |
</script> | |
<style type="text/css"> | |
body{font-size:13px} | |
.divFrame{width:345px;border:solid 1px #666} | |
.divFrame .divTitle{padding:5px;height:23px} | |
.divFrame .divTitle span{float:left;padding:2px;padding-top:5px;} | |
.divFrame .divContent{padding:8px} | |
.divFrame .divContent .clsShow{font-size:14px} | |
select,input{float:left} | |
.txt{border:#666 1px solid;padding:2px;width:80px;margin-right:3px} | |
.btn {border:#666 1px solid;padding:2px;width:50px; | |
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff, EndColorStr=#ECE9D8);} | |
</style> | |
<script type="text/javascript"> | |
$(function() { | |
$("#Button1").click(function() { //按钮单击事件 | |
//打开文件,并通过回调函数返回服务器响应后的数据 | |
$.post("User-Info.aspx", | |
$("#frmUserInfo").serialize(), //序列化表单数据 | |
function(data) { | |
$("#divTip") | |
.empty() //先清空标记中的内容 | |
.html(data); //显示服务器返回的数据 | |
}) | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
<form id="frmUserInfo"> | |
<div class="divFrame"> | |
<div class="divTitle"> | |
<span>姓名:</span> | |
<input name="txtName" type="text" class="txt" /> | |
<select name="selSex" style="height:22px;margin-right:3px"> | |
<option value="">选性别</option> | |
<option value="男">男</option> | |
<option value="女">女</option> | |
</select> | |
<input name="chkEmail" type="checkbox" value="1" style="padding-top:5px" /><span style="margin-right:10px">显示邮箱</span> | |
<input id="Button1" type="button" | |
class="btn" value="请求" /> | |
</div> | |
<div class="divContent"> | |
<div id="divTip"></div> | |
</div> | |
</div> | |
</form> | |
</body> | |
</html> | |
下面是post对应的user_info.aspx的数据
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%
string strName = System.Web.HttpUtility.UrlDecode(Request["name"]);//解码姓名字符
string strSex = System.Web.HttpUtility.UrlDecode(Request["sex"]);//解码性别字符
string strHTML = "<div class='clsShow'>"; //初始化保存内容变量
if (strName == "陶国荣" && strSex=="男")
{
strHTML += "姓名:陶国荣<br>";
strHTML += "性别:男<br>";
strHTML += "邮箱:[email protected]<hr>";
}
else if (strName == "李建洲" && strSex == "女")
{
strHTML += "姓名:李建洲<br>";
strHTML += "性别:女<br>";
strHTML += "邮箱:[email protected]<hr>";
}
strHTML += "</div>";
Response.Write(strHTML);
%>
下面是ajax方式的请求与发送数据
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$.ajax()方法发送请求</title>
<script type="text/javascript"
src="Jscript/jquery-1.4.2-vsdoc.js">
</script>
<script type="text/javascript"
src="Jscript/jquery-1.4.2.js">
</script>
<style type="text/css">
body{font-size:13px}
.divFrame{width:225px;border:solid 1px #666}
.divFrame .divTitle{padding:5px;height:23px}
.divFrame .divTitle span{float:left;padding:2px;padding-top:5px;}
.divFrame .divContent{padding:8px;text-align:center}
.divFrame .divContent .clsShow{font-size:14px;line-height:2.0em}
.divFrame .divContent .clsShow .clsError{font-size:13px;border:solid 1px #cc3300;padding:2px;display:none;margin-bottom:5px;background-color:#ffe0a3}
.txt{border:#666 1px solid;padding:2px;width:150px;margin-right:3px}
.btn {border:#666 1px solid;padding:2px;width:50px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff, EndColorStr=#ECE9D8);}
</style>
<script type="text/javascript">
$(function() {
$.ajax({ //请求登录页
url: "login.html", //登录静态页
dataType: "html",
success: function(HTML) { //返回页面内容
$("#frmUserLogin").html(HTML); //将页面内容置入表单
$("#btnLogin").click(function() { //“登录”按钮单击事件
//获取用户名称
var strTxtName = encodeURI($("#txtName").val());
//获取输入密码
var strTxtPass = encodeURI($("#txtPass").val());
//开始发送数据
$.ajax({ //请求登录处理页
url: "login.aspx", //登录处理页
dataType: "html",
//传送请求数据
data: { txtName: strTxtName, txtPass: strTxtPass },
success: function(strValue) { //登录成功后返回的数据
//根据返回值进行状态显示
if (strValue == "True") {
$(".clsShow").html("操作提示,登录成功!");
}
else {
$("#divError").show().html("用户名或密码错误!");
}
}
})
})
}
})
})
</script>
</head>
<body>
<form id="frmUserLogin"></form>
</body>
</html>
下面是login.aspx页面的内容
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%
string strName = System.Web.HttpUtility.UrlDecode(Request["txtName"]); //解码姓名字符
string strPass = System.Web.HttpUtility.UrlDecode(Request["txtPass"]); //解码密码字符
bool blnLogin = false;
if (strName == "admin" && strPass == "123456")
{
blnLogin = true;
}
Response.Write(blnLogin);
%>
下面是login.html页面的内容
<div class="divFrame">
<div class="divTitle">
<span>用户登录</span>
</div>
<div class="divContent">
<div class="clsShow">
<div id="divError" class="clsError"></div>
<div>名称:<input id="txtName" type="text" class="txt" /></div>
<div>密码:<input id="txtPass" type="password" class="txt" /></div>
<div>
<input id="btnLogin" type="button" value="登录" class="btn" />  
<input id="btnReset" type="reset" value="取消" class="btn" />
</div>
</div>
</div>
</div>
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>$.ajaxSetup()方法全局设置Ajax</title> | |
<script type="text/javascript" | |
src="Jscript/jquery-1.4.2-vsdoc.js"> | |
</script> | |
<script type="text/javascript" | |
src="Jscript/jquery-1.4.2.js"> | |
</script> | |
<style type="text/css"> | |
body{font-size:13px} | |
.divFrame{width:225px;border:solid 1px #666} | |
.divFrame .divTitle{padding:5px;height:30px} | |
.divFrame .divTitle span{float:left;padding:2px;padding-top:5px} | |
.divFrame .divContent{padding:8px} | |
.divFrame .divContent .clsShow{font-size:14px} | |
.txt{border:#666 1px solid;padding:2px;width:150px;margin-right:3px} | |
.btn {border:#666 1px solid;padding:2px;width:65px; | |
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff, EndColorStr=#ECE9D8);} | |
</style> | |
<script type="text/javascript"> | |
$(function() { | |
$.ajaxSetup({ //设置全局性的Ajax选项 | |
type: "GET", | |
url: "UserInfo.xml", | |
dataType: "xml" | |
}) | |
$("#Button1").click(function() { //"姓名”按钮的单击事件 | |
$.ajax({ | |
success: function(data) { //传回请求响应的数据 | |
ShowData(data, "姓名", "name"); //显示"姓名"部分 | |
} | |
}) | |
}) | |
$("#Button2").click(function() { //"性别”按钮的单击事件 | |
$.ajax({ | |
success: function(data) { //传回请求响应的数据 | |
ShowData(data, "性别", "sex"); //显示"性别"部分 | |
} | |
}) | |
}) | |
$("#Button3").click(function() { //"邮箱”按钮的单击事件 | |
$.ajax({ | |
success: function(data) { //传回请求响应的数据 | |
ShowData(data, "邮箱", "email"); //显示"邮箱"部分 | |
} | |
}) | |
}) | |
/* | |
*根据名称与值,获取请求响应数据中的某部分 | |
*@Param d为请求响应后的数据 | |
*@Param n为数据中文说明字符 | |
*@Param d为数据在响应数据中的元素名称 | |
*/ | |
function ShowData(d, n, v) { | |
$("#divTip").empty(); //先清空标记中的内容 | |
var strHTML = ""; //初始化保存内容变量 | |
$(d).find("User").each(function() { //遍历获取的数据 | |
var $strUser = $(this); | |
strHTML += n + ":" + $strUser.find(v).text() + "<hr>"; | |
}) | |
$("#divTip").html(strHTML); //显示处理后的数据 | |
} | |
}) | |
</script> | |
</head> | |
<body> | |
<div class="divFrame"> | |
<div class="divTitle"> | |
<span><input id="Button1" type="button" value="姓名" class="btn" /></span> | |
<span><input id="Button2" type="button" value="性别" class="btn" /></span> | |
<span><input id="Button3" type="button" value="邮箱" class="btn" /></span> | |
</div> | |
<div class="divContent"> | |
<div id="divTip" class="clsShow"></div> | |
</div> | |
</div> | |
</body> | |
</html>
下面是对应的xml文件
<?xml version="1.0" encoding="UTF-8"?>
-<Info>
-<User id="1">
<name>陶国荣</name>
<sex>男</sex>
<email>[email protected]</email>
</User>
-<User id="2">
<name>李建洲</name>
<sex>女</sex>
<email>[email protected]</email>
</User>
</Info>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>Ajax中的全局事件</title> | |
<script type="text/javascript" | |
src="Jscript/jquery-1.4.2-vsdoc.js"> | |
</script> | |
<script type="text/javascript" | |
src="Jscript/jquery-1.4.2.js"> | |
</script> | |
<style type="text/css"> | |
body{font-size:13px} | |
.divFrame{width:325px;border:solid 1px #666} | |
.divFrame .divTitle{padding:5px;height:30px} | |
.divFrame .divTitle span{float:left;padding:2px;padding-top:5px} | |
.divFrame .divContent{padding:8px} | |
.divFrame .divContent .clsShow{font-size:14px} | |
.divFrame .divContent .clsTip{width:160px;text-align:center;font-size:13px;border:solid 1px #cc3300;padding:2px;margin-bottom:5px;background-color:#ffe0a3} | |
.txt{border:#666 1px solid;padding:2px;width:160px;margin-right:3px} | |
.btn {border:#666 1px solid;padding:2px;width:65px; | |
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff, EndColorStr=#ECE9D8);} | |
</style> | |
<script type="text/javascript"> | |
$(function() { | |
//元素绑定全局ajaxStart事件 | |
$("#divMsg").ajaxStart(function() { | |
$(this).show(); //显示元素 | |
}) | |
//元素绑定全局ajaxStop事件 | |
$("#divMsg").ajaxStop(function() { | |
$(this).html("已成功获取数据。").hide(); | |
}) | |
//按钮的单击事件 | |
$("#Button1").click(function() { | |
$.ajax({ //带参数请求服务器 | |
type: "GET", | |
url: "GetData.aspx", | |
//获取加码后的数据并作为参数传给服务器 | |
data: { txtData: encodeURI($("#txtData").val()) }, | |
dataType: "html", | |
success: function(data) { //显示解码后的返回数据 | |
$("#divTip").html(decodeURI(data)); | |
} | |
}) | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
<div class="divFrame"> | |
<div class="divTitle"> | |
<span>数据:<input id="txtData" type="text" class="txt" /></span> | |
<span><input id="Button1" type="button" value="发送" class="btn" /></span> | |
</div> | |
<div class="divContent"> | |
<div id="divMsg" class="clsTip">正在发送数据请求…</div> | |
<div id="divTip" class="clsShow"></div> | |
</div> | |
</div> | |
</body> | |
</html>
下面是对应的getdata。aspx页面内容
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%
string strName = Request["txtData"]; //返回传回的参数
Response.Write(strName); //返回传回的参数
%>
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>新闻点评功能</title> | |
<script type="text/javascript" | |
src="Jscript/jquery-1.4.2-vsdoc.js"> | |
</script> | |
<script type="text/javascript" | |
src="Jscript/jquery-1.4.2.js"> | |
</script> | |
<link type="text/css" href="Css/css_Ajax.css" rel="Stylesheet" /> | |
<script type="text/javascript" src="Jscript/js_Ajax.js"></script> | |
</head> | |
<body> | |
<div class="divFrame"> | |
<div class="divTitle"> | |
<span>最新点评</span> | |
</div> | |
<div class="divContent"> | |
</div> | |
<div class="divSubmit"> | |
<div class="SubTitle">发表评论<span id="divMsg" class="clsTip">正在发送数据请求…</span></div> | |
<div class="SubContent"> | |
<textarea id="txtContent" rows="6" class="txt"></textarea> | |
<div class="SubBtn"> | |
<span style="float:left">用户名:<input id="txtName" type="text" class="txt" /></span> | |
<span style="float:right"><input id="Button1" type="button" value="发表" class="btn" /></span> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> | |