I am getting an error when I run this code this way...
var action = $("#action_button").html();
var results = [];
$('#main_form input').each(function(){
results.push({
this.id : this.value
});
});
var json = JSON.stringify(results);
... but I don't get the results I want when I execute it this way...
var action = $("#action_button").html();
var results = [];
$('#main_form input').each(function(){
results.push({
id:this.id
value: this.value
});
});
var json = JSON.stringify(results);
I want it to return:
{id: "22", first_name: "john", last_name: "smith"}
It is currently returning:
{"id":"id","value":"22"},{"id":"first_name","value":"john"},
{"id":"last_name","value":"smith"}