关于 jquery ajax 传接送格式 到 webservice 的问题!!!!
将代码贴出,请各位帮我看看什么问题!
ajax 传值到 websevice 的问题!
只要将 contextType改成 application/json 服务器端就会报错,难道是我json data 格式不对吗?
C# code
$.ajax({
type: "post",
url: "AjaxLoginAsmx.asmx/UpdataRowValue",
contentType: "application/json;charset=utf-8",
//
dateType: "json",
data: "({\"id\":\"" + this.id + "\",\"city\":\"" + city + "\",\"name\":\"" + name + "\",\"num\":\"" + num + "\"})",
success: function(de) { alert(de) },
error: function(html) { alert(html); }
});
webservice.asmx.cs
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string UpdataRowValue()
{
try
{
return serializer.Serialize(new success { successed = 1 });
}
catch (Exception ee)
{
return serializer.Serialize(new success { successed = 0 });
}
}
}
public class success
{
public int successed{get;set;}
}
------解决方案--------------------
参见完整的例子
http://dotnet.aspx.cc/file/jQuery-Ajax-Call-WebService-DataTable.aspx