简单的Json数据提交
jQuery ajax webservice:get 和 post
一、GET 方式
客户端
var data = { classCode: "0001"}; // 这里要直接使用JOSN对象
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "/WebServices/ProductPropertyWebService.asmx/GetProductPropertyList",
dataType: "json",
anysc: false,
data: data,
success: RenderProperties,
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown + ':' + textStatus); // 错误处理
}
});
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "/WebServices/ProductPropertyWebService.asmx/GetProductPropertyList",
dataType: "json",
anysc: false,
data: data,
success: RenderProperties,
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown + ':' + textStatus); // 错误处理
}
});
服务器端
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)] //UseHttpGet = true
public List<Property> GetProductPropertyList()
{
string classCode = HttpContext.Current.Request["classCode"]; // Get 方式,要在查询字符串里得到参数值
return PropertyManager.GetPropertySet(classCode, "zh-CN").DataList;
}
public List<Property> GetProductPropertyList()
{
string classCode = HttpContext.Current.Request["classCode"]; // Get 方式,要在查询字符串里得到参数值
return PropertyManager.GetPropertySet(classCode, "zh-CN").DataList;
}