I know it is possible to serialize and unserialize in PHP and then have javascript read the response, my question is can I do it the other way around? I have a function that may be called multiple times and each time it is called I need the new data added to an array or an object of some form. Then I want to take all of this data and send it to PHP to be interpreted and analyzed as if it were an array.
I think I am drawing a blank here, and this should be easily done xD Oh yeah and i am storing the information temporarily in a hidden field until it is ready for submission (I will be doing security checks in PHP as well)
Thanks :D
To make JavaScript serialize in the syntax of PHP's serialize would require a custom JavaScript function, however you can do what you want with JSON.
To serialize to JSON in JavaScript you would use the stringify method of the JSON object:
JSON.stringify(myArray)
and to unserialize a JSON string in PHP you would use json_decode:
json_decode($myJsonArray)
If you want to support older browsers, you will have to include an external implementation of the JSON object. See Browser-native JSON support
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With