So far, I’ve only been passing javascript strings to my web methods, which get parsed, usually as Guids. but now i have a method that accepts an IList… on the client, i build this array of objects and then attempt to pass it like:
$.ajax({ type: 'POST', url: 'personalization.aspx/SetPersonalization', data: '{'backerEntries':' + backerEntries + '}', contentType: 'application/json; charset=utf-8', dataType: 'json', success: postcardManager.SetPersonalizationComplete });
The post:
{'backerEntries':[object Object],[object Object],[object Object]}
The error response:
Invalid JSON primitive: object.
For some reason, jquery doesn’t seem to convert my array into a json string? Any ideas why? I tried putting [] around the backerEntries, and {}, as well as {[]} just in sheer desperation. Am I missing something obvious here?
..is the same as
…which is pretty much useless. Use Duncan‘s suggestion if you just want to pass an encoded list of values with the name ‘backerEntries’ in your querystring. If you want to JSON-encode the data, then get a JSON library and call
JSON.stringify().