0
我是一個通過ajax發送結果的表單。使用「提交按鈕」發送不是問題,但是當我更改「選擇」字段時,沒有數據被引用。它應該是一個「父母」問題,一些div和跨度位於輸入字段的周圍。 感謝您的幫助發送表單與父()。serialize()
<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>
解決方案提供一個id,形成元素,然後用連載方式發送數據,如$(「#formid」)。序列化() – 2014-11-22 09:32:38