Page1.aspx 有一个跨度元素“class1”,它触发一个针对“.click”事件的 Ajax 请求,这由 Page2.aspx 处理。Page2.aspx 使用“class2”呈现另一个 span 元素。单击“class2”会触发 Page3.aspx 上定义的另一个 Ajax 请求。
问题是,如何让 Page1.aspx 获取anotherid参数,以便处理它?所有结果都呈现回#results。
我一开始就做对了吗???
Page1.aspx (HTML):
<html>
<head>
<script type="text/javascript">
$(document).ready(function () {
$('.class1').click(function () {
$.ajax({
contentType: "text/html; charset=utf-8",
//detect span "class2" was clicked and append to url here?
//data: "id=" + this.id + ",anotherid=" + ???
data: "id=" + this.id,
url: "Page2.aspx",
dataType: "html",
success: function (data) {
$('#results').html(data);
}
});
});
});
</script>
</head>
<body>
<div><span class="class1" id="123">Click</span></div>
<div id="results"></div>
</body>
</html>
Page2.aspx(后面的代码):
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["id"];
Response.Write("<span class=\"class2\" id="456">" + id + "</span>");
}
Page2.aspx (HTML):
<html>
<head>
<script type="text/javascript">
$(document).ready(function () {
$('.class2').click(function () {
$.ajax({
contentType: "text/html; charset=utf-8",
data: "anotherid=" + this.id,
url: "Page3.aspx",
dataType: "html",
success: function (data) {
$('#results').html(data);
}
});
});
});
</script>
</head>
<body>
</body>
</html>
Page3.aspx(后面的代码):
protected void Page_Load(object sender, EventArgs e)
{
string tags = Request.QueryString["anotherid"];
//do something with anotherid.
}