请求带返回值和输出值的Web方法的JQuery Ajax
问题描述:
我有这种奇怪的情况,我在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
}
是这一种方式来应对这种情况呢?
答
我认为它不可能。在阿贾克斯现在
[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
}
..我做了一些愚蠢的错误在我的终点,而是你的建议的工作!!!!非常感谢..... –