[英]send form with parent().serialize()
i´ve a form which sends the result via ajax. 我有一个通过ajax发送结果的表格。 Sending with the "submit button" is not the problem, but when I change the "select" field, no data is submited. 使用“提交按钮”发送不是问题,但是当我更改“选择”字段时,不会提交任何数据。 It should be a "parent" problem, some divs and spans are around of the input field. 它应该是一个“父”问题,输入字段周围存在一些div和spans。 Thanks for help 感谢帮助
<form>
// calls the script by changing but no data is submited - there are some divs and spans around the "select"
<div id="e.g.">
<div>
<select id="version" size="1" name="version" class="change"><option value="1" selected>XXX</option><option value="2">YYY</option></select>
</div>
</div>
//calls the script by clicking and all datas are submited
<input id="submit_button" type="submit" value="Generate preview and HTML code">
</form>
<script>
$(function(){
function send() {
$.ajax({
type: "POST",
url: "script.pl",
data: $(this).parent().serialize(),
success: function(msg) {
$('#xyz').html(msg);
}
});
return false;
}
//send with the submit button
$("#submit_button").click(send);
//send when the select field is changed
$('.change').change(send);
});
</script>
自己找到解决方案
data: $('#id_of_the_form').serialize(),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.