开发者

How can I get this ajax request to post without error?

开发者 https://www.devze.com 2023-02-17 17:45 出处:网络
Why is the following not working? I keep getting the following 500 error. \"{\"Message\":\"Invalid JSON primitive: question.\",\"StackTrace\":\"at System.Web.Scri开发者_运维百科pt.Serialization.Java

Why is the following not working? I keep getting the following 500 error.

"{"Message":"Invalid JSON primitive: question.","StackTrace":" at System.Web.Scri开发者_运维百科pt.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n at "

// button submit
    $('#btnCreatePoll').click(function ()
    {
        var fields = $('#createPoll input').serializeArray();       

        $.ajax({
            type: "POST",
            url: "PollManagerCreatePoll.aspx/test",
            data: fields,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg)
            {
                // Do something interesting with msg.d here.
            }
        });
    });




  [WebMethod]
    public static void test (object data)
    {
        string test = "test";
    }


"PollManagerCreatePoll.aspx/test" doesn't make sense, unless you are using a URL rewrite to make "PollManagerCreatePoll.aspx" a directory. Do you mean "PollManagerCreatePoll.aspx?test" or "PollManagerCreatePoll.aspx"?

EDIT: Did you even search Google first? A quick search found this:

http://forum.jquery.com/topic/invalid-json-primitive-error-while-using-ajax

0

精彩评论

暂无评论...
验证码 换一张
取 消