Page1.aspx有一個span元素「class1」,它觸發了一個「.click」事件的Ajax請求,這由Page2.aspx處理。 Page2.aspx使用「class2」呈現另一個span元素。點擊「class2」觸發另一個在Page3.aspx上定義的Ajax請求。使用Ajax/JQuery/C#從子頁面將URL參數傳遞迴主頁?
問題是,我怎樣才能讓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.
}
我看不到'Page1.aspx'在'anotherid'上做了什麼。你的意思是'Page3.aspx'? –
我真的不明白你想要什麼,你面對的是什麼確切的問題/錯誤 –
嗨,對不起,它不明確。我沒有收到錯誤信息,因爲我不知道如何去做。我想要做的是通過「anotherid」回到Page1.aspx進行處理......我如何檢測從「Page1.aspx」中單擊的跨度「class2」?我在代碼中添加了一條註釋行,以使事情更加清晰... – RiceBucket