2010-09-28 25 views
1
function getMainContent(ID, num, lang){ 
$.ajax({ 
    type: "POST", 
    url: "WebMethods.aspx/showMain", 
    data: '{AID: "' + articleID+ '", ANum: "' +num + '"}', 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    success: showSuccess, 
    failure: function(response) { 
     alert(response); 
    } 
}); 

lang在我的頁面上以Session [「Lang」]形式提供。 如何訪問並將其發送到Web方法?將asp.net會話變量傳遞給通過jquery調用的Web方法

回答

7

您可以直接訪問會話頁面方法中:

[WebMethod(EnableSession = true)] 
public static string ShowMain() 
{ 
    var lang = HttpContext.Current.Session["Lang"]; 
    return "foo"; 
} 
+0

感謝達林。這工作。 – Churchill 2010-09-28 10:23:51

+0

謝謝...你節省了我的時間 – 2014-01-21 09:41:40