使用parent()发送表单.serialize()

时间:2014-11-22 09:22:11

标签: jquery ajax

我有一个通过ajax发送结果的表单。使用“提交按钮”发送不是问题,但是当我更改“选择”字段时,不会提交任何数据。它应该是一个“父”问题,一些div和spans在输入字段的周围。 谢谢你的帮助

            <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>

1 个答案:

答案 0 :(得分:0)

自己找到解决方案

data: $('#id_of_the_form').serialize(),