ajax實(shí)例入門代碼
更新時(shí)間:2008年11月18日 00:21:33 作者:
想學(xué)習(xí)ajax的朋友,如果剛開始接觸可以查看腳本之家的ajax欄目,之前的一些文章。
靜態(tài)頁面
復(fù)制代碼 代碼如下:
<!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>無標(biāo)題頁</title>
<script type="text/javascript" src="jquery/jquery.js" >
//這里不可以用<script type="" src="" />
</script>
<script type="text/javascript">
/*
encodeURI 方法
對URL傳遞的參數(shù)進(jìn)行編碼
將文本字符串編碼為一個(gè)有效的統(tǒng)一資源標(biāo)識符 (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)頁面
復(fù)制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write("后臺數(shù)據(jù)");
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"]);
}
相關(guān)文章
AJAX在不同瀏覽器中XMLHttpRequest對象的生成示例
本文為大家介紹下AJAX在不同瀏覽器中XMLHttpRequest對象是怎樣生成的,以方便我們針對不同瀏覽器進(jìn)行測試,感興趣的朋友可以參考下,希望對大家有所幫助2013-07-07django使用ajax post數(shù)據(jù)出現(xiàn)403錯誤如何解決
在django中,使用jquery ajax post數(shù)據(jù),會出現(xiàn)403的錯誤,該如何解決呢?下面由腳本之家小編幫大家解決django使用ajax post數(shù)據(jù)出現(xiàn)403錯誤,需要的朋友可以參考下2015-09-09ajax簡介_動力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要為大家詳細(xì)介紹了ajax基礎(chǔ)知識點(diǎn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06實(shí)例代碼講解ajax實(shí)現(xiàn)的無刷新分頁
這篇文章主要介紹了實(shí)例代碼講解ajax實(shí)現(xiàn)的無刷新分頁的相關(guān)資料,需要的朋友可以參考下2015-12-12