Calling asp.net webmethod with params from jquery errors

帅比萌擦擦* 提交于 2019-12-24 05:57:39

问题


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

            });

回答1:


Try enclosing your data parameter in quotes:

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


来源:https://stackoverflow.com/questions/936542/calling-asp-net-webmethod-with-params-from-jquery-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!