Jquery+ajax的简单使用
2014-05-13 14:30
267 查看
//前台页面:
<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" onclick="JqQueryGetTest();"/>
<input type="button" value="JqQueryPostTest" id="Button1" onclick="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相反
//前台页面:
<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" onclick="JqQueryGetTest();"/>
<input type="button" value="JqQueryPostTest" id="Button1" onclick="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相反
相关文章推荐
- 使用Jquery原理实现一个简单的Ajax的支持JS类
- jQuery使用ajax跨域获取数据的简单实例
- 使用jQuery的ajax功能简单示例
- 使用jquery实现简单的ajax
- 五滴水:使用Ajax+jQuery来实现前端收到的数据在console上显示+简单的主页设计与bootstrap插件实现图片轮播
- Jquery(Ajax) 调用 SharePoint 2013 Search Rest API 并使用Josn反回结果并简单显示
- asp.net MVC3 + JQuery 的ajax简单使用
- jquery中ajax的简单使用
- 学习新事物:使用jquery+xml实现ajax简单实例
- 使用jquery实现简单的ajax
- JQuery中ajax的简单使用教程(附带实例代码)
- jquery.$.ajax简单的使用
- jquery封装ajax(建议使用比较简单)
- thinkphp使用ajax、jquery、Mysql实现了简单的客户端通信功能
- jquery file upload ajax上传图片 简单使用
- jQuery使用ajax写个简单的请求
- Struts2学习笔记(二)使用jQuery—Ajax技术的简单Demo
- asp.net MVC3 + JQuery 的ajax简单使用
- thinkphp使用ajax、jquery、Mysql实现了简单的客户端通信功能
- JQuery使用Ajax的一个简单应用