开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜