2016-11-20 80 views
1

我有這種奇怪的情況,我在WebService中有一個WebMethod,它需要返回一個通用列表並且還需要將輸出參​​數附加到它。請求帶返回值和輸出值的Web方法的JQuery Ajax

$.ajax({ })需要調用此webservice並獲得返回值和outparameter在.success()

Web服務是如下:

[WebMethod] 
public static List <Category> GetAllCategory(out int TotalCountRecord) 
{ 
    List <Category> AllValues = new List <Category>(); 
    //Some ADO.NET Code to Call Stored Procedure with output Value; 
    SqlParameter OutParameter = new SqlParameter("@RecordCount", SqlDbType.Int); 
    OutParameter.Direction = ParameterDirection.Output; 
    cmd.ExecuteNonQuery(); 
    TotalCountRecord = (int)(OutParameter.Value); 
    //Pls. Don't Mind these sequence of the code. 
    return AllValues; 
} 

現在是對我有一種可能的方法來調用這些代碼jQuery的阿賈克斯一樣

var a = 0; 
$.ajax({ 
    url: 'WebService1.asmx/GetAllCategory', 
    method: 'post', 
    dataType: 'json', 
    data: JSON.stringify({TotalCountRecord: a}), 
    contentType: 'application/json; charset=utf-8', 
    success: function(data) { 

    //Add data to Table 
    //Show RecordCount at Footer of the Table 
    } 

是這一種方式來應對這種情況呢?

回答

1

我認爲它不可能。在阿賈克斯現在

[WebMethod] 
public static dynamic GetAllCategory(out int TotalCountRecord) 
{ 
List <Category> AllValues = new List <Category>(); 
//Some ADO.NET Code to Call Stored Procedure with output Value; 
SqlParameter OutParameter = new SqlParameter("@RecordCount",SqlDbType.Int); 
OutParameter.Direction = ParameterDirection.Output; 
cmd.ExecuteNonQuery(); 
TotalCountRecord = (int)(OutParameter.Value); 
//Pls. Don't Mind these sequence of the code. 
return new{AllValues,TotalCountRecord}; 
} 

可以返回輸出參數

success: function(data) { 
    Add data.AllValues to Table 
    Show data.TotalCountRecord at Footer of the Table 
} 
+0

..我做了一些愚蠢的錯誤在我的終點,而是你的建議的工作!!!!非常感謝..... –