Normally when I have an imput I use this syntax:
ensino: $('#amount').val()
开发者_JS百科But now I have a group of radio buttons:
<input type="radio" id="radio1" name="radios" value="1">
<label for="radio1">Politécnico</label>
<input type="radio" id="radio2" name="radios" value="2">
<label for="radio2">Universitário</label>
<input type="radio" id="radio3" name="radios" value="3">
<label for="radio3">Profissional</label>
<input type="radio" id="radio4" name="radios" value="4">
<label for="radio4">Outro</label>
How can I do an Ajax post? In this case, I can't use the id, correct?
Thanks.
I believe it would be $('*[name=radios]:checked').val()
.
Excerpt from http://api.jquery.com/jQuery.post/ :
Example: send form data using ajax requests
$.post("test.php", $("#testform").serialize());
You probably shouldn't be stitching together all the elements by hand, and can instead perform an ajax POST using jQuery's http://api.jquery.com/serialize/ function.
From: http://api.jquery.com/val/
$('input:radio[name=bar]:checked').val();
精彩评论