“Invalid JSON primitive” in Ajax processing

Just a guess what does the variable json contain after

var json = Sys.Serialization.JavaScriptSerializer.serialize(obj);?

If it is a valid json object like {"foo":"foovalue", "bar":"barvalue"} then jQuery might not send it as json data but instead serialize it to foor=foovalue&bar=barvalue thus you get the error "Invalid JSON primitive: foo"

Try instead setting the data as string

    data: '{"foo":"foovalue", "bar":"barvalue"}', //note the additional quotation marks

This way jQuery should leave the data alone and send the string as is to the server which should allow ASP.NET to parse the json server side.

Leave a Comment