If I had this structure
var data =
{
"people": [
{ "name" : "John", "id" : 1 },
{ "name" : "Marc", "id" : 2 }
]
}
I want to add more elements to this, in JavaScript, specifically in jQuery to then send it like this
var dataString = JSON.stringify(data);
$.post('some.php', { data: dataString}, showResult, "text");
var data =
{
"people": [
{ "name" : "John", "id" : 1 },
{ "name" : "Marc", "id" : 2 }
]
}
data["people"].push({"name": "foo", "id": 3});
console.log(data);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.