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

发布于 2024-07-23 11:29:52 字数 846 浏览 3 评论 0原文

我设法设置了一个简单的 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');
                }

            });

I managed to setup a simple webmethod which i called from jquery and sure enough it returns ... then i added parameters on the method and added the params to jquery but it errors with

        Message":"Invalid JSON primitive: one.","StackTrace":"

my signature on my webmethod is like so

    [WebMethod]
    public static string GetDate(string one, string two)
    {
        return "yes";
    }

and my jquery is like this, what am i doing wrong?

                $.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');
                }

            });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆流 2024-07-30 11:29:52

尝试将数据参数括在引号中:

data: '{ one: "value", two: "value" }',

Try enclosing your data parameter in quotes:

data: '{ one: "value", two: "value" }',
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文