1
我試圖將從我的母版頁點擊的語言類型發送到surfacecontroller
App_code
文件夾中。我的HTML是這樣如下:Jquery Ajax調用發送數據的方法,當href點擊
<div class="navbar-topbar clearfix">
<div class="h5 pull-right">
<span class="linkCA">
<strong>CA</strong>
<a class="lang=en-CA" href="@NewUrlLink">EN</a> |
<a class="lang=fr-CA" href="@NewUrlLink">FR</a>
</span>
<span class="linkUS">
<strong>US</strong>
<a class="lang=en-US" href="@NewUrlLink">EN</a>
</span>
</div>
</div>
所以我在想什麼是獲得類名,並通過AJAX調用被點擊的a
時發送。我有這樣的方法,我想通過語言的類型點擊到:
public string GetDictionaryItemByCulture(string key, string language)
{
var currentLang = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
var otherLang = myCulture(language);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(otherLang);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(otherLang);
// String noLastSegment = Request.Url.AbsolutePath;
string x = new UmbracoHelper().GetDictionaryValue(key);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(currentLang);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(currentLang);
return x;
}
我看到這個AJAX方法在網上,它看起來像我需要什麼,但我不知道如何把它與我需要工作。
$(document).ready(function() {
// Add the page method call as an onclick handler for the div.
$("#Result").click(function() {
$.ajax({
type: "POST",
url: "Default.aspx/GetDate",
data: { someParameter: "some value" },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.d);
}
});
});
});