views:

349

answers:

1

Hi there,

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

            });
+4  A: 

Try enclosing your data parameter in quotes:

data: '{ one: "value", two: "value" }',
Brandon Montgomery
data: "{ 'one':'value', 'two':'value'}" would also work. +1
ichiban