gpt4 book ai didi

asp.net - 使用 jquery 错误中的参数调用 asp.net webmethod

转载 作者:行者123 更新时间:2023-12-01 07:36:37 25 4
gpt4 key购买 nike

我设法设置了一个简单的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com