我认为这应该是一个简单的事情,但由于某种原因,除了下拉列表的选定值之外,我的所有表单值都被序列化了,表格如下:
<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="example@domain.com" 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@me.com\u0026amp; comment = quick test所以我不知道为什么下拉值没有被提取.
谢谢你的帮助.
您的下拉列表需要提交包含的name属性.
<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>
希望这可以帮助!