靜態(tài)頁面
復制代碼 代碼如下:
!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(),
//發(fā)送GET請求
function(data){
$("#serverResponse").html(decodeURI(data));
}
);
}
function doRequestUsingPOST(){
$.post("AjaxServe.aspx",createQueryString(),
//發(fā)送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>
動態(tài)頁面
復制代碼 代碼如下:
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"]);
}