Reputation: 13395
I've got a simple form
<form class="form-horizontal" id="new-tag-form">
<div class="form-group">
<label for="inputTagName" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputTagName">
</div>
</div>
</form>
And a button
<button id="create-tag" type="button" class="btn btn-primary">Create</button>
I want to post form (send json
data) when I click on that button. To do that I added a function
$('#create-tag').click(function() {
$.post(
"/tags-rest/tag",
$('#new-tag-form').serialize(),
function(data) {
alert(data);
}
);
});
But when I click on that button - it sends request without any data from the form. What is the problem?
Upvotes: 0
Views: 42
Reputation: 171679
Only form controls that have a name
attribute ever get sent to server using browser default submit process or included in serialize()
The name
is used for the key in key/value pairs
<input type="text" class="form-control" id="inputTagName" name="tagname">
Upvotes: 3