我有一個@Ajax.ActionLink
替換他自己的包裝,另一個內容也有@Ajax.ActionLink
,返回第一個html內容包裝。這是部分鏈接,取代它的自我和反之亦然。我的問題是,當我需要點擊動作鏈接時,我的jquery返回舊部分,已經點擊,而不是新的,在螢火蟲我清楚地看到我的新元素,但無法達到他們,我試過了, OnSuccess和OnComplete,但沒有成功!有任何想法嗎?獲取Mvc3 Ajax.ActionLink用Jquery替換數據?
這裏的例子:
VIEW
index.cshtml
<div id="box">
@Html.Partial("_PartialOne")
</div>
_ PartialOne.cshtml
@Ajax.ActionLink("Get partial two", "getPartial2", "Home",
new AjaxOptions
{
UpdateTargetId = "box",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
},
new { @class="first"}
)
<div id="testBox1">Hello, I am partial 1</div>
_ PartialTwo.cshtml
@Ajax.ActionLink("Get partial one", "getPartial1","Home",
new AjaxOptions
{
UpdateTargetId = "box",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
},
new { @class="second"}
)
<div id="testBox2">Hello there this is partial 2</div>
控制器
HomeController.cs
public PartialViewResult getPartial1()
{
return PartialView("_PartialOne");
}
public PartialViewResult getPartial2()
{
return PartialView("_PartialTwo");
}
JS
$("#box a.first").live('click', function() {
//how to fetch new data, that was filled with getPartial2()
console.log($(this).parent().children());
//this returns [a.first, div#testBox1]
// and I need [a.second, div#testBox2]
});
如何選擇返回的數據,讓我們說子字符串,如果neccesary?
EDIT
使用的onComplete = 「功能」
VIEW
@Ajax.ActionLink("Get partial two", "getPartial2", "Home",
new AjaxOptions
{
UpdateTargetId = "box",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET",
OnComplete = "getNewData"
},
new { @class="first"}
)
<div id="testBox1">Hello, I am partial 1</div>
JS
function getNewData()
{
console.log($(this));
//this returns [Object] of ajax call, niether
// $(this).parent/s(), or $(this).children() is posible
}
如何選擇調用此ajax元素的子元素?
@Darin Dimitrov,你可以看看這個... – 2012-02-01 13:59:25
作爲jQuery 1.7,.live()已被棄用。你應該使用.on()。 http://api.jquery.com/live/ – 2012-02-01 14:00:00
@ZachGreen,謝謝,但這並不能解決這個問題? – 2012-02-01 14:06:54