2010-03-30 103 views
4

我正在使用jQuery的ASP.NET頁面方法。這裏是我的代碼,如何將int值傳遞給jQuery的ASP.NET頁面方法?

$.ajax({ 
     type: "POST", 
     url: "Default.aspx/GetRecords", 
     data: "{}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 

和ASP.NET頁面方法,

[WebMethod] 
public static string GetRecords(int currentPage,int pagesize) 
{ 
    // my logic here 
} 

如何傳遞值從jQuery的currentPagepagesize

回答

6

我明白了。我的數據部分必須是

data: "{'currentPage':1,'pagesize':5}", 
0

你嘗試只是:

$.ajax({ 
    type: "POST", 
    url: "Default.aspx/GetRecords", 
    data: {"currentPage": 1, "pageSize": 100}, 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 

+0

@codeka似乎不工作... – 2010-03-30 04:17:57

+0

@codeka該方法不會被調用.. – 2010-03-30 04:18:16

+0

@codeka螢火蟲它'500內部服務器錯誤' – 2010-03-30 04:20:53

0

通過檢查時試試這個

$.ajax({ 
     type: "POST", 
     contentType: "application/json; charset=utf-8", 
     data: "{ currentPage: '" +parseInt($('#currentpage').val()) + "',pageSize:'"+parseInt($('#pagesize').val()) +"'}", 
     url: "Default.aspx/GetRecords", 
     dataType: "json", 
     success: function (data) { 
        $("#result").html(data.d); 
       } 
     }); 
相關問題