I have a JSON Array that is defined as follows:
var myItems = {
"data": [
{ "id":1, "firstName":"bill", "lastName":"smith" },
{ "id":2, "firstName":"john", "lastName":"apple" },
{ "id":3, "firstName":"will", "lastName":"long"}
]
};
I need to store this array in a hidden HTML element so that I can pass it to my server-side code in string format. My problem, I'm not sure how to do this. Can someone tell me how to do this?
Thank you!
Essentially, you want to serialize your array into json, and then specify where you want to store the resulting string value..
document.getElementById('yourHiddenField').value = jsonString;
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