我设法设置了一个简单的 webmethod,我从 jquery 调用它,果然它返回...然后我在方法上添加了参数并将参数添加到 jquery,但出现错误
Message":"Invalid JSON primitive: one.","StackTrace":"
我的 webmethod 上的签名是这样的
[WebMethod]
public static string GetDate(string one, string two)
{
return "yes";
}
我的jquery是这样的,我做错了什么?
$.ajax({
type: "POST",
url: "MyService.aspx/GetDate",
data: { one: "value", two: "value" },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
},
error: function(msg) {
alert('error');
}
});
最佳答案
尝试将数据参数括在引号中:
data: '{ one: "value", two: "value" }',
关于asp.net - 使用 jquery 错误中的参数调用 asp.net webmethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/936542/