欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

傳遞參數(shù)的標(biāo)準(zhǔn)方法(jQuery.ajax)

 更新時(shí)間:2008年11月19日 16:04:55   作者:  
jQuery.ajax傳遞參數(shù)的方法
前臺(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>無(wú)標(biāo)題頁(yè)</title>
<script type="text/javascript" src="jquery/jquery-1.2.6.js"></script>
<script type="text/javascript">
//這個(gè)方法把a(bǔ)jax方法封裝一下,方便調(diào)用。
function myajax(){
//用此法傳遞數(shù)據(jù)
var arr={
"name":"tree",
"id":"123"
};
$.get(
"ajax.aspx",
arr,
callback,
"json"
);
}
//回調(diào)函數(shù)
function callback(data){
$('#response').append(data.name+data.id);
$('#wait').css("display","none");
}
//onload()事件
$(function(){
$('#confirm').click(myajax);
})
//封裝json數(shù)據(jù),為了代碼清晰,看來(lái)這種方法不行。
/* 似乎是因?yàn)閿?shù)組格式不對(duì)。
var dataStr=jsonData();
alert(dataStr);
*/
function jsonData(){
var jsonStr="";
jsonStr+="\"name\":";
jsonStr+="\"tree\"";
jsonStr+=",";
jsonStr+="\"id\":";
jsonStr+="\"123\"";
jsonStr+="}";
return jsonStr;
}
</script>
</head>
<body>
<div id="confirm">點(diǎn)擊</div>
<div id="response">接收后臺(tái)數(shù)據(jù)</div>
<div id="wait" class="hide">hello</div>
</body>
</html>

后臺(tái) 
復(fù)制代碼 代碼如下:

public partial class ajax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write("hello"+Request["name"]);
Hashtable ht = new Hashtable();
ht.Add("name", Request.Params["name"]);
ht.Add("id", Request.Params["id"]);
Response.Write(CreateJsonParams(ht));
Response.End();
}
private string CreateJsonParams(Hashtable items)
{
string returnStr = "";
foreach (DictionaryEntry item in items)
{
returnStr += "\"" + item.Key.ToString() + "\":\"" + item.Value.ToString() + "\",";
}
return "{" + returnStr.Substring(0, returnStr.Length - 1) + "}";
}
}

相關(guān)文章

最新評(píng)論