对于 asmx,您需要传递数据对象的字符串化版本,例如:
var data = "{param1:" + param1IsANumber +
", param2:\"" + param2IsAString + "\"}";
$.ajax({
data: data,
dataType: "json",
url: url,
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (result) {}
});
或者你可以有一个对象并使用jquery-json http://code.google.com/p/jquery-json/
var data = {};
data.param1 = 1;
data.param2 = "some string";
$.ajax({
data: jQuery.toJSON(data),
dataType: "json",
url: url,
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (result) {}
});
最后,您的 Web 服务类必须如下所示:
[WebService(Namespace = "http://www.somedomainname.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class MyService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void MyServiceCall(int param1, string param2)
{
}
}