i have a usual form. the only thing i'm trying to differently is group 3 of the input values into a json. and when i click on submit, i want to send other inputs as usual but those 3 as one json. I have made it into json using jquery but unable to understand how to send it on submit click. Please see my code and let me know what's missing. (FYI i'm working on spring mvc) i have this form:
<form class="form-horizontal" action="success" method="post" role="form">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" placeholder="Name" value="">
<input type="text" name="dob" id="dob" class="form-control" placeholder="Date of Birth" value="">
</div>
<div class="row form-group">
<div class="col-sm-3">
<input type="text" id="school_name" class="form-control" placeholder="school/college name" />
</div>
<div class="col-sm-3">
<select class="form-control year" id="year">
<option>1</option>
<option>2</option>
</select>
</div>
<div class="col-sm-3">
<input type="text" class="form-control" id="qualification" placeholder="qualification" />
</div>
<div class="col-sm-3">
<button type="button" class="btn btn-primary" id="add" value="add">Add More</button>
</div>
</div>
<input type="submit" class="btn btn-danger form-control" id="save" value="Save">
</form>
and my jquery code is:
$(document).on('click',"#save",function() {
var $items = $('#school_name, #year,#qualification ')
var education=null;
var json = {}
$items.each(function() {
json[this.id] = $(this).val();
});
education= JSON.stringify(json);
alert(education) //this gives me the required result
window.location="success?education="+education;
// I guess something is wrong here
});