*.cs(Webservice)
---------------------------------------------------------------------------------------
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
[WebMethod]
public string CommentList(int PageSize, int PageIndex, int ProductID)
{
List<veping.Model.Product_Comment> pcModelList = new List<veping.Model.Product_Comment>();
veping.Model.Product_Comment pcModel = new veping.Model.Product_Comment();
SqlParameter[] param = new SqlParameter[]
{
new SqlParameter("@PageSize",PageSize),
new SqlParameter("@PageIndex",PageIndex),
new SqlParameter("@ProductID",ProductID),
new SqlParameter("@bit",0)
};
try
{
DataSet ds = new DataSet();
ds = DAAB.SqlHelper.ExecuteDataset(db.Return_Connection(), CommandType.StoredProcedure, "UP_SearchProductComment", param);
//return ds;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
pcModel.Title = ds.Tables[0].Rows[i]["Title"].ToString();
pcModel.Content = ds.Tables[0].Rows[i]["Content"].ToString();
pcModel.UserName = ds.Tables[0].Rows[i]["UserName"].ToString();
pcModel.ThisTime = DateTime.Parse(ds.Tables[0].Rows[i]["ThisTime"].ToString());
pcModelList.Add(pcModel);
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
string result = serializer.Serialize(pcModelList);
return result;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
*.htm
---------------------------------------------------------------------------------------
<script language="javascript">
function GetList(psize,pindex,pid) {
Ext.Ajax.request({
url: 'http://localhost:10726/veping/vp_webservice.asmx/CommentList', // Webservice的地址以及方法名
contentType:"application/json;utf-8",
jsonData: { PageSize: psize, PageIndex: pindex,ProductID: pid }, // json 形式的参数
method: 'POST', // poste 方式传递
success: onSuccess,
failure: onFailure
});
}
//成功
function onSuccess(request, options) {
// 服务器返回json形式的结果
//var result = Ext.util.JSON.decode( eval('(' +request.responseText+ ')'));
document.write(request.responseText);
}
//失败
function onFailure(request, options) {
document.write("Error:" + request.responseText);
}
</script>
返回结果:
---------------------------------------------------------------------------------------
"[{\"Title\":\"\",\"Content\":\"9折优惠,真正的实惠!\",\"ThisTime\":\"\\/Date(1251153713000)\\/\"},
{\"Title\":\"\",\"Content\":\"9折优惠,真正的实惠!\",\"ThisTime\":\"\\/Date(1251153713000)\\/\"},
{\"Title\":\"\",\"Content\":\"9折优惠,真正的实惠!\",\"ThisTime\":\"\\/Date(1251153713000)\\/\"}]"
return result;
---------------------------------------------------------------------------------------
relace()函数无法替换,C#和javascript都试过了,希望大家能给出解决方案,谢谢了!