自分自身のラッパーを置き換える@Ajax.ActionLink
を持っています。もう1つのコンテンツは@Ajax.ActionLink
で、最初のhtmlコンテンツをラッパーに返します。それは自己とその逆の部分に取って代わる部分的な部分へのリンクです。私の問題は、ActionLinkへのクリック時にいくつかの追加機能を必要とするとき、私のJqueryは古い部分、クリックされた部分、新しい部分ではなく、Firebugで新しい要素をはっきりと見るが、 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>
CONTROLLER
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]
});
返されたデータを選択して、必要な場合は部分文字列を指定する方法
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と呼ばれる要素の子供を選択するにはどうすればよいですか?
@ダーリンディミトロフ、これをご覧になれますか。 –
jQuery 1.7以降、.live()は推奨されていません。 .on()を使うべきです。 http://api.jquery.com/live/ –
@ZachGreen、ありがとうございます。でも、この問題は解決しませんか? –