Serialize Json 2-dimensional Array, Send Two Arrays, Or Other?
I have to send a 2-dimensional array (along with several other variables) to PHP using jQuery.ajax(). I believe my options are: Serialize to json with JSON-js Send both arrays a
Solution 1:
You can try :
JSON.stringify(array);
No extra library required.
Solution 2:
I'm sure there are other options; there's always a million ways to skin a cat. But I'd suggest option #1. When you send it as a JSON string (using a library that is quite small and only has two methods), you can then decode it in PHP using json_decode. No fuss, no muss.
Solution 3:
A. Is there anything wrong with option #2 if I'd prefer not to include another library for a small function?
You might have issues with escaping/unescaping some characters.
B. Are there other options besides options #1 and #2?
Surely there must be. But I'd go with JSON, it's the simplest and cleanest solution.
Post a Comment for "Serialize Json 2-dimensional Array, Send Two Arrays, Or Other?"