//前台页面:
<script src="js/jquery-1.3.2.js" type="text/javascript"></script>
<script type="text/javascript">
function JqQueryPostTest() {
$.ajax({
type: "post",
url: "Test.ashx?type=post",
data: "username=lisi&&age=90",
datatype: "text",
success: function(data) {
alert(data);
},
error: function(data) {
alert("失败!");
}
})
}
function JqQueryGetTest() {
$.ajax({
type: "get",
url: "Test.ashx?type=get",
data: "username=lisi&&age=90",
datatype: "text",
success: function(data) {
alert(data);
},
error: function(data) {
alert("失败!");
}
})
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="username" />
<br />
<input type="text" id="age" />
<br />
<input type="button" value="JqQueryGetTest" id="btn" οnclick="JqQueryGetTest();"/>
<input type="button" value="JqQueryPostTest" id="Button1" οnclick="JqQueryPostTest();"/>
<div id="result">
</div>
</form>
</body>
.ashx 页面
public class Test1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
context.Response.Write(CheckPost(context));
}
public string CheckPost(HttpContext context)
{
string lei = context.Request["type"];
string re = string.Empty;
if (lei == "get")
{
string name = context.Request["username"];
string age = context.Request["age"];
re = "get方式访问("+name+"--"+age+")";
}
if (lei == "post")
{
string name = context.Request["username"];
string age = context.Request["age"];
re = "post方式访问(" + name + "--" + age + ")";
}
return re;
}
public bool IsReusable
{
get
{
return false;
}
}
}
区别的话,
总之,GET方式传送数据量小(1KB左右),处理效率高,安全性低,会被缓存,而POST相反