我认为这应该是一件简单的事情,但由于某种原因,除了下拉列表的选定值之外,我的所有表单值都被很好地序列化,表单如下:
<form id="contactform">
<label for="name">Name</label>
<input type="text" id=name name=name placeholder="First and last name" tabindex="1" />
<label for="phonenumber">Phone Number</label>
<input type="text" id=phonenumber name=phonenumber placeholder="Please enter your phone number" tabindex="2" />
<label for="email">Email</label>
<input type="text" id=email name=email placeholder="[email protected] /cdn-cgi/l/email-protection" tabindex="3" />
<label for="dropdown">Please Confirm:</label>
<select>
<option value="question" selected="selected">I have a question</option>
<option value="attending">I am attending</option>
<option value="not-attending">I am not attending</option>
</select>
<label for="comment">Your Message</label>
<textarea name="comment" id=comment name=comment placeholder="Enter something here, can't think" tabindex="5"></textarea>
<input name="submit" type="submit" id="submit" tabindex="6" value="Send Message"/>
</form>
这就是我序列化它的方式:
$('#contactform').submit(function() {
var query = $(this).serialize();
$.ajax({
type: "POST",
url: "send.php",
data: query,
success: function(data) { // rest of function
最后,我用来将值设置为变量的 PHP 部分是:
$dropdown = $_POST['dropdown'];
一个示例标头是name=sgrggr&phonenumber=55555555555&email=me%40me.com&comment=quick+test
所以我不知道为什么下拉值没有被拾取。
感谢您的帮助。
您的下拉列表需要一个名称属性才能包含在提交中。
<select name="dropdown">
<option value="question" selected="selected">I have a question</option>
<option value="attending">I am attending</option>
<option value="not-attending">I am not attending</option>
</select>
希望这可以帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)