实例入门(ajax)
2008-11-17 14:44
381 查看
静态页面
<!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="jquery/jquery.js" >
//这里不可以用<script type="" src="" />
</script>
<script type="text/javascript">
/*
encodeURI 方法
对URL传递的参数进行编码
将文本字符串编码为一个有效的统一资源标识符 (URI)。
*/
function createQueryString(){
var firstName=encodeURI($("#firstName").val());
var birthday=encodeURI($("#birthday").val());
//组合成对象的形式
var queryString={firstName:firstName,birthday:birthday};
return queryString;
}
function doRequestUsingGET(){
$.get("AjaxServe.aspx",createQueryString(),
//发送GET请求
function(data){
$("#serverResponse").html(decodeURI(data));
}
);
}
function doRequestUsingPOST(){
$.post("AjaxServe.aspx",createQueryString(),
//发送POST请求
function(data){
$("#serverResponse").html(decodeURI(data));
}
);
}
</script>
</head>
<body>
<h2>输入姓名和生日</h2>
<form>
<input type="text" id="firstName" /><br />
<input type="text" id="birthday" />
<input type="button" value="GET" onclick="doRequestUsingGET();" /><br />
<input type="button" value="POST" onclick="doRequestUsingPOST();" />
</form>
<div id="serverResponse"></div>
</body>
</html>
动态页面
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write("后台数据");
if (Request.HttpMethod == "POST")
Response.Write("POST:" + Request["firstName"] + ",your birthday is" + Request["birthday"]);
else if(Request.HttpMethod=="GET")
Response.Write("GET:" + Request["firstName"] + ",your birthday is" + Request["birthday"]);
}
<!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="jquery/jquery.js" >
//这里不可以用<script type="" src="" />
</script>
<script type="text/javascript">
/*
encodeURI 方法
对URL传递的参数进行编码
将文本字符串编码为一个有效的统一资源标识符 (URI)。
*/
function createQueryString(){
var firstName=encodeURI($("#firstName").val());
var birthday=encodeURI($("#birthday").val());
//组合成对象的形式
var queryString={firstName:firstName,birthday:birthday};
return queryString;
}
function doRequestUsingGET(){
$.get("AjaxServe.aspx",createQueryString(),
//发送GET请求
function(data){
$("#serverResponse").html(decodeURI(data));
}
);
}
function doRequestUsingPOST(){
$.post("AjaxServe.aspx",createQueryString(),
//发送POST请求
function(data){
$("#serverResponse").html(decodeURI(data));
}
);
}
</script>
</head>
<body>
<h2>输入姓名和生日</h2>
<form>
<input type="text" id="firstName" /><br />
<input type="text" id="birthday" />
<input type="button" value="GET" onclick="doRequestUsingGET();" /><br />
<input type="button" value="POST" onclick="doRequestUsingPOST();" />
</form>
<div id="serverResponse"></div>
</body>
</html>
动态页面
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write("后台数据");
if (Request.HttpMethod == "POST")
Response.Write("POST:" + Request["firstName"] + ",your birthday is" + Request["birthday"]);
else if(Request.HttpMethod=="GET")
Response.Write("GET:" + Request["firstName"] + ",your birthday is" + Request["birthday"]);
}
相关文章推荐
- AJAX基础入门实例教程(含代码)
- AJAX 简介及入门实例
- 【转载】AJAX技术简介及入门实例
- AJAX技术简介及入门实例
- AJAX 入门视频之 Ext 2.0.1 Grid 增删改 & DWR 1 实例
- jquery_ajax 入门实例
- AJAX实例:XHR的入门
- ajax 入门实例
- AJAX入门必读与实例(仿google的拖动)[Code]
- 案例4-3 Ajax的响应处理简单实例(征服Ajax——Web 2.0快速入门与项目实践Java)
- 原生AJAX入门讲解(含实例)
- [AJAX]:入门小实例,走进AJAX
- AJAX实例入门
- Ajax入门实例第一篇 (Ajax.NET组件使用第一篇)
- Ajax入门实例(ASP+AJAX)
- AJAX实例入门
- ajax 入门经典实例
- AJAXControlToolKit控件入门实例之PopupControl
- AJAX入门教程实例