If I have say 1-5 variables on the client side that are needed server side and I handle my communications via ajax (Post Method) there are two major ways I can get them there.
- Using JSON to encode ( and later decode them ) and send as a JSON string in a POST variable
or
- Just create a POST variable for each variable I need to send.
Does it matter or is it just preference?
There will definitely be an overhead for deserializing JSON, but not much. I find that JSON is far preferable to creating new variables for every value you want to send. Plus I find that once your JSON implementation is in place, scaling is much easier (ie., when you have to add new values later for whatever reason).